用来定义 形状的 Drawable,根节点 shape,子节点比较多
属性
shape 下的属性
- android:shape:rectangle(矩形) ,ring (圆),line (线),oval (椭圆)
- visible:设置是否可见 感觉没效果
- android:innerRadius 内圆半径
- innerRadiusRatio 内圆半径比率
- thickness 当shape为ring才有效,表示环的厚度,即外半径与内半径的差
- thicknessRatio 当shape为ring才有效,表示环的厚度,即外半径与内半径的差
- useLevel:当shape为ring才有效,表示是否允许根据level来显示环的一部分,设置为false
solid 填充色
- android:color="@color/color06"
stroke 边框
- width 边框宽度
- color 边框颜色
- dashWidth 虚线 显示部分宽度
- dashGap 虚线缺口的宽度
corners 圆角
- radius 圆角半径,四个角一致
- topLeftRadius 左上角半径
- topRightRadius 右上角半径
- bottomLeftRadius 左下角半径
- bottomRightRadius 右下角半径
size 大小
- width 宽
- height 高
padding
- left,top,right,bottm:依次是左上右下方向上的边距!
gradient 渐变色
- startColor 开始颜色
- endColor结束颜色
- centerColor中间色
- angle:只有linear类型的渐变才有效,表示渐变角度,必须为45的倍数哦
- type:渐变类型,可选(linear,radial,sweep), 线性渐变(可设置渐变角度),发散渐变(中间向四周发散),平铺渐变
- centerX:渐变中间亚瑟的x坐标,取值范围为:0~1
- centerY:渐变中间颜色的Y坐标,取值范围为:0~1
- gradientRadius:只有radial和sweep类型的渐变才有效,radial必须设置,表示渐变效果的半径
- useLevel:判断是否根据level绘制渐变效果
rectangle 矩形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners android:radius="50dp"/>
<solid android:color="@color/color06"/>
</shape>
ring 环
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring" //环,画圆还是用oval 吧
android:useLevel="false"//这个必须设置false
android:innerRadius="350px"//内环半径
android:thickness="5dp"//圆环边框宽度
>
<solid android:color="@color/color02"/> 设置环的填充色
渐变色的环,从左到右
<gradient
android:startColor="#ffffff"
android:endColor="#000000"
/>
</shape>