下面是摘自官方文档的shape XML文档的属性总揽。
shape可设置的形状
rectangle:矩形。最常用的形状
oval:椭圆
line:直线。通常用于分割线的时候
ring:环形。
<?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="float" android:centerY="float" 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>
shape包含的属性
1、corners
这个仅仅用于当<shape>标签中的android:shape属性为rectangle的时候使用。可以使矩形边角呈一定弧度
另外,topLeftRadius等会覆盖设置的总的radius
这是设置radius为20dp,topLeftRadius和topRightRadius设置为80dp的结果。(为了突出效果,所以丑了点)
2、gradient
设置渐变效果
android:type(渐变类型):分为linear(线性),radial(辐射),sweep(扫描式)
·radial和sweep两种方式都需要设置radientRadius
·linear类型可以设置android:angle属性,来改变线性渐变的角度。其值必须是45的倍数
centerX:设置开始渐变的X坐标,(范围0-1.0)
centerY:设置开始渐变的Y坐标,(范围0-1.0)
3、padding
内边距
4、size
形状大小
5、solid
填充色,形状的颜色
6、stroke
形状的描边
当同时设置以下两个属性时,描边则为虚线表示
android:dashGap 描边的间隔宽度
android:dashWidth 虚线的宽度