给TextView加边框

来源:互联网 发布:2018年云计算展会 编辑:程序博客网 时间:2024/05/01 00:27
写drawable里面的xml文件,里面设置shape来设置文本框的特殊效果。

[java] view plaincopyprint?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.   
  4.     <!-- 实心 -->  
  5.     <solid android:color="@android:color/white" />  
  6.     <!-- 边框 -->  
  7.     <stroke  
  8.         android:width="0.5dp"  
  9.         android:color="@android:color/black" />  
  10.     <!-- 圆角 -->  
  11.     <corners android:radius="3dp" />  
  12.     <!-- 边距 -->  
  13.     <padding  
  14.         android:bottom="10dp"  
  15.         android:left="10dp"  
  16.         android:right="10dp"  
  17.         android:top="10dp" />  
  18.     <!-- 渐变 -->  
  19.     <gradient  
  20.         android:angle="270"  
  21.         android:endColor="#FFFF782"  
  22.         android:startColor="#13C7AF" />  
  23.   
  24. </shape>  

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


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

[java] view plaincopyprint?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="horizontal" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:layout_weight="1"  
  11.         android:background="@drawable/tvbar"  
  12.         android:text="hello" />  
  13.   
  14.     <TextView  
  15.         android:layout_width="wrap_content"  
  16.         android:layout_height="wrap_content"  
  17.         android:layout_weight="1"  
  18.         android:background="@drawable/tvbar"  
  19.         android:text="hello" />  
  20.   
  21.     <TextView  
  22.         android:layout_width="wrap_content"  
  23.         android:layout_height="wrap_content"  
  24.         android:layout_weight="1"  
  25.         android:background="@drawable/tvbar"  
  26.         android:text="hello" />  
  27.   
  28. </LinearLayout>  

下面是实现的效果。

0 0
原创粉丝点击