一、元素属性
元素:
<shape>
-
定义这是一个GradientDrawable,必须作为根元素。(ShapeDrawable gradientDrawable=(ShapeDrawable)textView.getBackground();这个时候会报错,只能转为GradientDrawable )
属性:
-
String类型。必须的,定义xml文件的命名空间,必须是"http://schemas.a
ndroid.com/apk/res/android"
. -
关键字。定义shape的值,必须是下面的之一:
值 描述 "rectangle"
矩阵,这也是默认的shape "oval"
椭圆 "line"
一条水平的直线。这种shape必须使用 <stroke>
元素来定义这条线的宽度"ring"
圆环。这种shape必须使用 <stroke>
元素来定义这条线的宽度
xmlns:android
android:shape
下面的属性只有当
android:shape="ring"
才使用:- 尺寸。 内环的半径。一个尺寸值(dip等等)或者一个尺寸资源。
-
Float类型。这个值表示内部环的比例,例如,如果android:innerRadiusRatio = " 5 ",那么内部的半径等于环的宽度除以5。这个值会被android:innerRadius重写。 默认值是9。
- 尺寸。环的厚度,是一个尺寸值或尺寸的资源。
- Float类型。厚度的比例。例如,如果android:thicknessRatio= " 2 ",然后厚度等于环的宽度除以2。这个值是被android:innerRadius重写, 默认值是3。
android:innerRadius
android:innerRadiusRatio
android:thickness
android:thicknessRatio
android:useLevel
Boolean类型。如果用在
LevelListDrawable
里,那么就是true。如果通常不出现则为false。<corners>
-
String类型。必须的,定义xml文件的命名空间,必须是"http://schemas.a
-
为Shape创建一个圆角,只有shape是rectangle时候才使用。
属性:
- Dimension。圆角的半径。会被下面每个特定的圆角属性重写。
-
Dimension。top-left 圆角的半径。
- Dimension。top-right 圆角的半径。
- Dimension。 bottom-left圆角的半径。
- Dimension。bottom-right圆角的半径。
android:radius
android:topLeftRadius
android:topRightRadius
android:bottomLeftRadius
android:bottomRightRadius
注意:每个圆角半径值都必须大于1,否侧就没有圆角。
下面的话不明白,我直接设置圆角为0就可以不圆了,其余的设置有圆角,一样的可行。不知道它为什么要这么讲。
-
(If you want specific cornersto not be rounded, a work-around is to use
android:radius
to set a default cornerradius greater than 1, but then override each and every corner with the values you reallywant, providing zero ("0dp") where you don't want rounded corners.) -
<gradient>
-
它与<solid>标签是互相排斥的,其中solid表示纯色填充,而gradient表示渐变效果
-
指定这个shape的渐变颜色。
属性:
- Integer。渐变的角度。 0 代表从 left 到 right。90 代表bottom到 top。必须是45的倍数,默认为0
- Float。渐变中心的相对X坐标,在0到1.0之间。
- Float。渐变中心的相对Y坐标,在0到1.0之间。
- Color。可选的颜色值。基于startColor和endColor之间。
- Color。 结束的颜色。
-
Float 。渐变的半径。只有在
android:type="radial"
才使用 - Color。开始的颜色值。
-
Keyword。渐变的模式,下面值之一:
值 描述 "linear"
线形渐变。这也是默认的模式 "radial"
辐射渐变。startColor即辐射中心的颜色 "sweep"
扫描线渐变。 - Boolean。如果在LevelListDrawable中使用,则为true
android:angle
android:centerX
android:centerY
android:centerColor
android:endColor
android:gradientRadius
android:startColor
android:type
android:useLevel
<padding>
内容与视图边界的距离
-
属性:
- Dimension。左边填充距离.
- Dimension。顶部填充距离.
- Dimension。右边填充距离.
- Dimension。底部填充距离.
android:left
android:top
android:right
android:bottom
<size>
-
这个shape的大小。
属性:
- Dimension。这个shape的高度。
- Dimension。这个shape的宽度。
android:height
android:width
注意:默认情况下,这个shape会缩放到与他所在容器大小成正比。当你在一个ImageView中使用这个shape,你可以使用
android:scaleType
="center"
来限制这种缩放。<solid>
-
填充这个shape的纯色
属性:
- Color。颜色值,十六进制数,或者一个Color资源
android:color
<stroke>
-
这个shape使用的笔画,当android:shape="line"的时候,必须设置改元素。
属性:
-
Dimension。笔画的粗细。
- Color。笔画的颜色
-
Dimension。每画一条线就间隔多少。只有当
android:dashWidth
也设置了才有效。 -
Dimension。每画一条线的长度。只有当
android:dashGap
也设置了才有效。
android:width
android:color
android:dashGap
android:dashWidth
-
Dimension。笔画的粗细。