手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android开发教程之view组件添加边框示例
android开发教程之view组件添加边框示例
摘要:给TextureView添加边框(专业名词为描边),有三种解决方案:1.设置一个9patch的,右边框,中间是空的PNG。2.自定义一个Vi...

给TextureView添加边框(专业名词为描边),有三种解决方案:

1.设置一个9 patch 的,右边框,中间是空的PNG。

2.自定义一个View,用Canvas画个边框。

3.用Android提供的ShapeDrawable来定义一个边框。

个人比较建议采用第三种方式,原因是因为第三种只要写XML,速度快,占用资源小,代码编写量也少,便于维护。

使用方法如下:

1.定义一个background.xml文件。

复制代码 代码如下:

<?xml version="1.0" encoding="UTF-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

<stroke

android:width="2dp"

android:color="#0000AA" />

</shape> <span></span>

2.在View的src设置背景时使用就可以了。

复制代码 代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center"

android:src="@drawable/background"

android:padding="2dp">

<TextureView

android:layout_width="match_parent"

android:layout_height="match_parent"/>

<com.android.camera.ui.RotateLayout

android:layout_width="wrap_content"

android:layout_width="wrap_content">

<TextView

android:layout_width="wrap_content"

android:layout_width="wrap_content"

android:textColor="#FFFFFF"

android:textSize="22sp"

android:background="#0000000"/>

</com.android.camera.ui.RoateLayout>

</RelativeLayout>

需要注意的是我给TextureView的父容器RelativeLayout设置了Drawable,并设置了Padding。

【android开发教程之view组件添加边框示例】相关文章:

Android开发笔记之:在ImageView上绘制圆环的实现方法

android开发基础教程—打电话发短信

android开发之方形圆角listview代码分享

android 开发教程之日历项目实践(一)

Android开发之软键盘用法实例分析

Android开发技巧之ViewStub控件惰性装载

Android开发笔记之:Splash的实现详解

android开发基础教程—三种方式实现xml文件解析

Android开发之线性布局

Android开发之WebView组件的使用解析

精品推荐
分类导航