给TextView加边框

来源:互联网 发布:vb.net 多线程带参数 编辑:程序博客网 时间:2024/05/16 15:56

先写drawable里面的xml文件,里面设置shape来设置文本框的特殊效果。

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <!-- 实心 -->    <solid android:color="@android:color/white" />    <!-- 边框 -->    <stroke        android:width="0.5dp"        android:color="@android:color/black" />    <!-- 圆角 -->    <corners android:radius="3dp" />    <!-- 边距 -->    <padding        android:bottom="10dp"        android:left="10dp"        android:right="10dp"        android:top="10dp" />    <!-- 渐变 -->    <gradient        android:angle="270"        android:endColor="#FFFF782"        android:startColor="#13C7AF" /></shape>

基本上常用的就这几种了,要达到很好的效果,你需要重新细致的改写里面的数据。


下面是要用到这个shape的LineLayout,在里面设置了3个TextView,没设置对其的方式,默认是向做靠齐的。

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal" >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_weight="1"        android:background="@drawable/tvbar"        android:text="hello" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_weight="1"        android:background="@drawable/tvbar"        android:text="hello" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_weight="1"        android:background="@drawable/tvbar"        android:text="hello" /></LinearLayout>

下面是实现的效果。


原创粉丝点击