Android中Shape Drawable在xml中的使用
来源:互联网 发布:java电影院售票系统 编辑:程序博客网 时间:2024/05/18 14:23
关于Shape使用的官方文档:
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
Android中常常使用shape来定义控件的一些显示属性,下面是Shape中的所有属性及一个简单的示例:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape=["rectangle" | "oval" | "line" | "ring"] > <corners android:radius="integer" android:topLeftRadius="integer" android:topRightRadius="integer" android:bottomLeftRadius="integer" android:bottomRightRadius="integer" /> <gradient android:angle="integer" android:centerX="integer" android:centerY="integer" android:centerColor="integer" android:endColor="color" android:gradientRadius="integer" android:startColor="color" android:type=["linear" | "radial" | "sweep"] android:useLevel=["true" | "false"] /> <padding android:left="integer" android:top="integer" android:right="integer" android:bottom="integer" /> <size android:width="integer" android:height="integer" /> <solid android:color="color" /> <stroke android:width="integer" android:color="color" android:dashWidth="integer" android:dashGap="integer" /></shape>
下面是一个小示例:
main.xml文件内容如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:paddingLeft="40dip" >
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_selector" android:text="TestShapeButton" />
</LinearLayout>
button_selector.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中Shape Drawable在xml中的使用
- Android中Shape Drawable在xml中的使用
- Android中Shape 在xml中的使用
- Android中drawable使用Shape资源
- Android Drawable中shape的使用
- Android中Shape、selector在xml中的使用、切换按钮的背景图案
- Android中在xml中使用shape美化UI
- Android中各种颜色在drawable.XML中的字符表示
- shape在Android中的使用
- Android Drawable中shape详解
- drawable中android:shape的
- Android shape Drawable的使用
- drawable中shape的使用
- Android 使用xml定义Drawable--第一篇:概述以和Shape Drawable示例
- Android xml 效果之 Shape Drawable
- 使用Drawable资源--在xml中定义
- Android中的XML drawable
- Android 中使用xml定义各种Drawable
- 在考察一家创业公司时,VC会考虑的11种风险
- StringUtils工具类的常用方法
- 使Android Home键,Power键等按钮失效
- jsp相对路径及servlet请求
- Win 7下定位kernel32.dll基址及shellcode编写
- Android中Shape Drawable在xml中的使用
- 远程桌面连接后实现copy文件的3个办法
- Unity发布android错误:Bundle Identifier has not been set up correctly
- Java中的IO整理完整版(二)
- Android -- AppWidget 高级篇
- 协同过滤推荐算法之Slope One的介绍
- 2012.6.18
- lr脚本调试
- 获取墙的一个侧面,并且将上的点坐标转换到XOY面在墙侧面上的坐标系