Android实现圆角边框

设置边框圆角能够在drawable-mdpi目录里定义一个xml: android

  1. <?xml version="1.0" encoding="utf-8"?>  ide

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

  3.     <solid android:color="#000000" />    orm

  4.     <corners android:topLeftRadius="10dp"   xml

  5.                     android:topRightRadius="10dp"    ip

  6.                 android:bottomRightRadius="10dp"   utf-8

  7.                 android:bottomLeftRadius="10dp"/>    string

  8. </shape>  it


解释:solid的表示填充颜色,为了简单,这里用的是黑色。 
而corners则是表示圆角,注意的是这里bottomRightRadius是左下角而不是右下角,bottomLeftRadius右下角。 
固然上面的效果也能够像下面同样设置,以下: io

  1. <corners android:radius="5dp" />  


若是想引用这个xml,只须要@drawable/corners_bg.xml便可: 

  1. android:background="@drawable/corners_bg"  



main.xml: 

  1. <?xml version="1.0" encoding="utf-8"?>  

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

  3.     android:orientation="vertical" android:layout_width="fill_parent"  

  4.     android:layout_height="fill_parent" android:background="#FFFFFF">  

  5.     <RelativeLayout android:id="@+id/login_div"  

  6.         android:layout_width="fill_parent" android:layout_height="150dip"  

  7.         android:padding="15dip" android:layout_margin="15dip"  

  8.         android:background="@drawable/corners_bg">  

  9.     </RelativeLayout>  

  10. </LinearLayout>  



运行结果: 

相关文章
相关标签/搜索