Android学习之——实现圆角Button

  在drawable文件夹下新建btn_shape.xml文件:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <shape xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:shape="rectangle">
 4     <solid android:color="#ffffff"/>
 5     <corners
 6         android:topLeftRadius="8dip"
 7         android:topRightRadius="8dip           
 8         android:bottomLeftRadius="8dip"
 9         android:bottomRightRadius="8dip"/>
10 </shape>

 先解释一下上面的代码:

     1.shape用于定义形状,有四种形状(矩形rectangle| 椭圆oval | 直线line | 圆形ring)。

     2.solid用于设置填充形状的颜色。

     3.corners用于创建圆角(只用于形状是矩形)。

                

    topLeftRadius、topRightRadius、bottomLeftRadius、bottomRightRadius分别设置左上,右上,左下,右下圆角的半径。

    使用方法:

               android:background="@drawable/btn_shape"

1   <Button
2         android:layout_width="wrap_content"
3         android:layout_height="wrap_content"
4         android:id="@+id/button"
5         android:background="@drawable/btn_shape"
6         />

  效果图:

        

 

1 参考网址:
2 http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

 

posted @ 2015-03-01 19:19  onerepublic  阅读(7355)  评论(2编辑  收藏  举报