android shape的应用
android shape的使用Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有
android shape的使用
Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结:
先看下面的代码:
我们还可以把描边弄成虚线的形式,设置方式为:
android:dashWidth="5dp"
android:dashGap="3dp"
其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。
corners:圆角
android:radius为角的弧度,值越大角越圆。
我们还可以把四个角设定成不同的角度,方法为:
?
复制到剪贴板??XML/HTML代码
- <?xml?version="1.0"?encoding="utf-8"?>??<selector??
- ????xmlns:android="http://schemas.android.com/apk/res/android">??????<item?android:state_pressed="true"?>??
- ????????<shape>??????????????<!--?渐变?-->??
- ????????????<gradient??????????????????android:startColor="#ff8c00"??
- ????????????????android:endColor="#FFFFFF"??????????????????android:type="radial"??
- ????????????????android:gradientRadius="50"?/>??????????????<!--?描边?-->??
- ????????????<stroke??????????????????android:width="2dp"??
- ????????????????android:color="#dcdcdc"??????????????????android:dashWidth="5dp"??
- ????????????????android:dashGap="3dp"?/>??????????????<!--?圆角?-->??
- ????????????<corners??????????????????android:radius="2dp"?/>??
- ????????????<padding??????????????????android:left="10dp"??
- ????????????????android:top="10dp"??????????????????android:right="10dp"??
- ????????????????android:bottom="10dp"?/>??????????</shape>??
- ????</item>??????<item?android:state_focused="true"?>??
- ????????<shape>??????????????<gradient??
- ????????????????android:startColor="#ffc2b7"??????????????????android:endColor="#ffc2b7"??
- ????????????????android:angle="270"?/>??????????????<stroke??
- ????????????????android:width="2dp"??????????????????android:color="#dcdcdc"?/>??
- ????????????<corners??????????????????android:radius="2dp"?/>??
- ????????????<padding??????????????????android:left="10dp"??
- ????????????????android:top="10dp"??????????????????android:right="10dp"??
- ????????????????android:bottom="10dp"?/>??????????</shape>??
- ????</item>??????<item>????????
- ????????<shape>??????????????<solid?android:color="#ff9d77"/>??
- ????????????<stroke??????????????????android:width="2dp"??
- ????????????????android:color="#fad3cf"?/>??????????????<corners??
- ????????????????android:topRightRadius="5dp"??????????????????android:bottomLeftRadius="5dp"??
- ????????????????android:topLeftRadius="0dp"??????????????????android:bottomRightRadius="0dp"??
- ????????????/>??????????????<padding??
- ????????????????android:left="10dp"??????????????????android:top="10dp"??
- ????????????????android:right="10dp"??????????????????android:bottom="10dp"?/>??
- ????????</shape>??????</item>??
- </selector>??
转自:http://dev.10086.cn/cmdn/wiki/index.php?doc-view-6087.html