shape的用法广泛,属性较多,有时候容易忘记,统计一下:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
</shape>
shape值有:rectangle(四边形),oval(椭圆),line(线),ring(圆环)
shape值为ring的时候需要注意注意三个属性innerRadius,thickness,useLevel:android:
useLevel 只有shape使用在LevelListDrawable中的时候,这个值为true,否则为false。当shape为ring的时候必须设置这个属性为false
innerRadius 内环的半径
thickness 环的厚度,也就是外环半径-内环半径
innerRadiusRatio; 默认值为3,内环半径的比例,例如这个值=2,那么内环的半径就是环的宽度1/2,通常这个值都会大于2,否则就显示不全环了,可以被innerRadius覆盖
thicknessRatio:如果android:thicknessRatio=”2”,那么环的厚度就等于环的宽度除以2。可以被thickness覆盖的
<!--填充色-->
<solid android:color="#ffff00"/>
<!--圆角-->
<corners
android:radius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"/>
<!--内边距-->
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<!--大小-->
<size
android:width="14dp"
android:height="14dp" />
<!--通作为background时size通常不会有效,当作为imageview的src的时size有效-->
<!--描边-->
<stroke
android:width="描边厚度"
android:color=描边颜色"
android:dashWidth="将描边分为多个dash,每隔dash块的宽度"
android:dashGap="dash块的间隔"/>
gradient渐变,这个单独拎出来讲:
默认的startColor可能为白色也可能是黑色~不同的手机默认不同
默认的渐变type为linear
radial的渐变类型必须要添加属性android:gradientRadius;
android:startColor=”“ 开始渐变颜色
android:endColor=”“ 结束渐变的颜色
android:centerColor=”“ 中间颜色
android:centerX=”“ 渐变中心x的相对位置 0-1
android:centerY=”“ 渐变中心y的相对位置 0-1
android:useLevel=”“ boolean 默认false,建议false
android:angle=”“ int 渐变开始角度,必须是45的倍数 linear
android:type=”“ linear,radial,sweep 线性渐变(默认)/放射渐变/扫描式渐变
android:gradientRadius=”“ 渐变半径