Android中Shape 在xml中的使用
2014-11-12 11:22
381 查看
关于Shape使用的官方文档:
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
Android中常常使用shape来定义控件的一些显示属性,下面是Shape中的所有属性:
这里给个按钮的背景风格例子:but_style.xml
源代码链接
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
Android中常常使用shape来定义控件的一些显示属性,下面是Shape中的所有属性:
1.<?xml version="1.0" encoding="utf-8"?> 2.<shape 3. xmlns:android="http://schemas.android.com/apk/res/android" 4. android:shape=["rectangle" | "oval" | "line" | "ring"] > 5. <corners 6. android:radius="integer" 7. android:topLeftRadius="integer" 8. android:topRightRadius="integer" 9. android:bottomLeftRadius="integer" 10. android:bottomRightRadius="integer" /> 11. <gradient 12. android:angle="integer" 13. android:centerX="integer" 14. android:centerY="integer" 15. android:centerColor="integer" 16. android:endColor="color" 17. android:gradientRadius="integer" 18. android:startColor="color" 19. android:type=["linear" | "radial" | "sweep"] 20. android:useLevel=["true" | "false"] /> 21. <padding 22. android:left="integer" 23. android:top="integer" 24. android:right="integer" 25. android:bottom="integer" /> 26. <size 27. android:width="integer" 28. android:height="integer" /> 29. <solid 30. android:color="color" /> 31. <stroke 32. android:width="integer" 33. android:color="color" 34. android:dashWidth="integer" 35. android:dashGap="integer" /> 36.</shape>
这里给个按钮的背景风格例子:but_style.xml
<?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:endColor="#FFFFFF" android:gradientRadius="50" android:startColor="#ff8c00" android:type="radial" /> <!-- 描边 --> <stroke android:dashGap="3dp" android:dashWidth="5dp" android:width="2dp" android:color="#dcdcdc" /> <!-- 圆角 --> <corners android:radius="2dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape> </item> <item android:state_focused="true"> <shape> <gradient android:angle="270" android:endColor="#ffc2b7" android:startColor="#ffc2b7" /> <stroke android:width="2dp" android:color="#dcdcdc" /> <corners android:radius="2dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape> </item> <item> <shape> <solid android:color="#ff9d77" /> <stroke android:width="2dp" android:color="#fad3cf" /> <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="0dp" android:topLeftRadius="0dp" android:topRightRadius="5dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape> </item> </selector>
源代码链接
相关文章推荐
- android View使用shape作为背景不能指定单边圆角的xml
- Android中在xml中使用shape美化UI
- Android xml中shape(画图)的使用
- Android下基于XML的Graphics shape使用方法
- android shape.xml 文件使用
- Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)
- Android中Shape Drawable在xml中的使用
- Android 使用xml定义Drawable--第一篇:概述以和Shape Drawable示例
- Android shape drawable XML 可绘制图形的创建与使用
- Android中Shape Drawable在xml中的使用
- Android中Shape、selector在xml中的使用、切换按钮的背景图案
- Android之XML的shape使用
- Android shape drawable XML 可绘制图形的创建与使用
- android 使用xml制作背景图片(shape的用法)
- 在 Android 上使用 XML
- android开发时 使用android layout editor 打开xml时eclipse自动关闭
- 【整理】Android中使用XML自定义组件各种状态下的背景图片
- 在 Android 应用程序中使用 Internet 数据 解析 XML、JSON 和 protocol buffers 数据
- 在 Android 上使用 XML 和 JSON,第 1 部分: 在 Android 应用程序上研究 JSON 和 XML 益处
- 在 Android 上使用 XML