Shape美化
用途
使用shape来定义android控件的一些显示属性。
常见属性
<shape>
<!--实心填充-->
<solid android:color="#ffff77" />
<!--渐变填充
angle:渐变角度,必须是45的整数倍
type:渐变模式,默认为线性渐变(linear)>>linear radial sweep
gradientRadius:指定渐变半径,当type为径向渐变(radial)时需要定义该属性
centerX:渐变的水平中心点,值为0-1.0
centerY:渐变的垂直中心点,值同上
centerColor:中心的颜色
usesLevel:true || false 功能不详
-->
<gradient
android:startColor="#ff8c00"
android:endColor="#FFFFFF"
android:angle="270" />
<!--描边
dashWidth:一个横线的宽度
dashGap:每个横线间隔开的距离
-->
<stroke
android:width="2dp"
android:color="#000000" />
<!--圆角
topRightRadius:右上角的圆角弧度
bottomLeftRadius topLeftRadius(此处指的是你所看到的右下角) bottomRightRadius
-->
<corners
android:radius="2dp" />
<!--间距-->
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
<!--背景大小-->
<size
android:width="30dp"
android:height="45dp" />
</shape>
实例
shape_btn_test.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TestShapeButton"
android:background="@drawable/btn_selector"
/>
btn_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: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>