首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android shape的应用

2012-07-02 
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代码
  1. <?xml?version="1.0"?encoding="utf-8"?>??<selector??
  2. ????xmlns:android="http://schemas.android.com/apk/res/android">??????<item?android:state_pressed="true"?>??
  3. ????????<shape>??????????????<!--?渐变?-->??
  4. ????????????<gradient??????????????????android:startColor="#ff8c00"??
  5. ????????????????android:endColor="#FFFFFF"??????????????????android:type="radial"??
  6. ????????????????android:gradientRadius="50"?/>??????????????<!--?描边?-->??
  7. ????????????<stroke??????????????????android:width="2dp"??
  8. ????????????????android:color="#dcdcdc"??????????????????android:dashWidth="5dp"??
  9. ????????????????android:dashGap="3dp"?/>??????????????<!--?圆角?-->??
  10. ????????????<corners??????????????????android:radius="2dp"?/>??
  11. ????????????<padding??????????????????android:left="10dp"??
  12. ????????????????android:top="10dp"??????????????????android:right="10dp"??
  13. ????????????????android:bottom="10dp"?/>??????????</shape>??
  14. ????</item>??????<item?android:state_focused="true"?>??
  15. ????????<shape>??????????????<gradient??
  16. ????????????????android:startColor="#ffc2b7"??????????????????android:endColor="#ffc2b7"??
  17. ????????????????android:angle="270"?/>??????????????<stroke??
  18. ????????????????android:width="2dp"??????????????????android:color="#dcdcdc"?/>??
  19. ????????????<corners??????????????????android:radius="2dp"?/>??
  20. ????????????<padding??????????????????android:left="10dp"??
  21. ????????????????android:top="10dp"??????????????????android:right="10dp"??
  22. ????????????????android:bottom="10dp"?/>??????????</shape>??
  23. ????</item>??????<item>????????
  24. ????????<shape>??????????????<solid?android:color="#ff9d77"/>??
  25. ????????????<stroke??????????????????android:width="2dp"??
  26. ????????????????android:color="#fad3cf"?/>??????????????<corners??
  27. ????????????????android:topRightRadius="5dp"??????????????????android:bottomLeftRadius="5dp"??
  28. ????????????????android:topLeftRadius="0dp"??????????????????android:bottomRightRadius="0dp"??
  29. ????????????/>??????????????<padding??
  30. ????????????????android:left="10dp"??????????????????android:top="10dp"??
  31. ????????????????android:right="10dp"??????????????????android:bottom="10dp"?/>??
  32. ????????</shape>??????</item>??
  33. </selector>??

转自:http://dev.10086.cn/cmdn/wiki/index.php?doc-view-6087.html

热点排行