Android中Shape Drawable在xml中的使用
2012-06-18 16:17
330 查看
关于Shape使用的官方文档:
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
Android中常常使用shape来定义控件的一些显示属性,下面是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内容如下:
效果图如下:
一般状态:
按下状态:
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 使用xml定义Drawable--第一篇:概述以和Shape Drawable示例
- Android shape drawable XML 可绘制图形的创建与使用
- Android shape drawable XML 可绘制图形的创建与使用
- Android中Shape Drawable在xml中的使用
- Android Shape Drawable 静态使用和动态使用(圆角,渐变实现)
- Android Studio2.2在drawable文件夹创建xml的shape文件
- Android下基于XML的Graphics shape使用方法
- Android中drawable使用Shape资源
- 【转】Android UI美化之Shape Drawable的使用
- shape 的使用(drawable xml文件中定义的一个几何图形)
- 关于android中drawable文件夹下各类xml样式文件的使用详解
- android 使用xml制作背景图片(shape的用法)
- android 使用xml drawable 实现 局部圆角,可用作圆角边框
- Android Drawable Resources 之 Shape Drawable 使用详解
- android shape.xml 文件使用
- 在drawable下的xml文件中layer-list的用二:在layer-list下的item标签中使用shape画图,以及backgroun和src的区别
- Android xml中shape(画图)的使用
- Android中在xml中使用shape美化UI
- Android必知必会--使用shape制作drawable素材
- Android中Shape、selector在xml中的使用、切换按钮的背景图案