当前位置: 移动技术网 > IT编程>移动开发>Android > android开发教程之view组件添加边框示例

android开发教程之view组件添加边框示例

2019年07月24日  | 移动技术网IT编程  | 我要评论

国企美妇征途,房虫网,绝命时刻南征北战

给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。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网