Android shape属性
2019-07-31 本文已影响0人
无敌未央様
一.基本属性
平常使用的几个常见属性大概就是:corners、solid、stroke、gradient、padding、size,其中前三个用的比较多
1.corners
这个属性是用来定义圆角的,可以把像Button等控件的四个角变的圆滑。
属性的数值会影响这个圆角有多圆
<corners //定义圆角
android:radius="dimension" //全部的圆角半径
android:topLeftRadius="dimension" //左上角的圆角半径
android:topRightRadius="dimension" //右上角的圆角半径
android:bottomLeftRadius="dimension" //左下角的圆角半径
android:bottomRightRadius="dimension" /> //右下角的圆角半径
注意:radius和它下面四个属性不能共用
2.solid
这个属性就是内部填充色,它只有一个属性color
<solid android:color="color" />
3.stroke
stroke主要是用来描边的,我们给一个控件描上什么颜色的边,描上的边是虚线还是实线,如果是虚线它的间隔该有多大等等问题我们可以用stroke来解决。
<stroke
android:width="dimension" //描边的宽度
android:color="color" //描边的颜色
// 以下两个属性设置虚线
android:dashWidth="dimension" //虚线的宽度,值为0时是实线
android:dashGap="dimension" /> //虚线的间隔
4.gradient
gradient用以定义渐变色,可以定义两色渐变和三色渐变,及渐变样式.
<gradient
//共有3中渐变类型,线性渐变(默认)/放射渐变/扫描式渐变
android:type=["linear" | "radial" | "sweep"]
//渐变角度,针对线性渐变,必须为45的倍数,0为从左到右,90为从上到下
android:angle="integer"
//渐变中心X的相当位置,范围为0~1
android:centerX="float"
//渐变中心Y的相当位置,范围为0~1
android:centerY="float"
//渐变开始点的颜色
android:startColor="color"
//渐变中间点的颜色,在开始与结束点之间 ,不定义就是双色渐变
android:centerColor="color"
//渐变结束点的颜色
android:endColor="color"
//渐变的半径,只有当渐变类型为radial时才能使用
android:gradientRadius="float"
//使用LevelListDrawable时就要设置为true。设为false时才有渐变效果
android:useLevel=["true" | "false"] />
我们在type中可以定义渐变的类型是什么,linear是线性渐变,radial是放射性渐变,sweep是扫描性渐变。

5.shape
shape自身标签也带有一些属性,用来定义这个控件的形状。
android:shape=["rectangle" | "oval" | "line" | "ring"]
shape的形状,默认为矩形,可以设置为矩形(rectangle)、椭圆形(oval)、线性形状(line)、环形(ring)
下面的属性只有在android:shape="ring时可用:
//尺寸,内环的半径。
android:innerRadius
// 浮点型,以环的宽度比率来表示内环的半径.
android:innerRadiusRatio
//尺寸,环的厚度
android:thickness
//浮点型,以环的宽度比率来表示环的厚度,例如,如果android:thicknessRatio="2",
android:thicknessRatio
// boolean值,如果当做是LevelListDrawable使用时值为true,否则为false.
android:useLevel