Shape Drawable This is a generic shape defined in XML.
这是一个通用的XML中定义的形状
file location: res/drawable/filename.xml
位置:res/drawable/文件的名称.xml The filename is used as the resource ID.
compiled resource datatype: Resource pointer to a GradientDrawable. resource reference: In Java: R.drawable.filename In XML: @[package:]drawable/filename
Keyword. Defines the type of shape. Valid values are:(矩形、椭圆、直线、环形)
Value
Desciption
"rectangle"
A rectangle that fills the containing View. This is the default shape.
"oval"
An oval shape that fits the dimensions of the containing View.
"line"
A horizontal line that spans the width of the containing View. This shape requires the <stroke> element to define the width of the line.
"ring"
A ring shape.
The following attributes are used only when android:shape="ring":(定义的几何形状为环形时候, shape节点还可以有如下的属性设置;这里需要特别注意的是:这里不能设置环的外半径,只能设置内 半径和环形的厚度(即外半径减掉内半径)。)
android:innerRadius(内环的半径)
Dimension. The radius for the inner part of the ring (the hole in the middle), as a dimension valueor dimension resource.
android:innerRadiusRatio(内环半径比例)
Float. The radius for the inner part of the ring, expressed as a ratio of the ring's width. For instance, if android:innerRadiusRatio="5", then the inner radius equals the ring's width divided by 5. This value is overridden by android:innerRadius. Default value is 9.
Dimension. The thickness of the ring, as a dimension value or dimension resource.
android:thicknessRatio(环形厚度的比例)
Float. The thickness of the ring, expressed as a ratio of the ring's width. For instance, if android:thicknessRatio="2", then the thickness equals the ring's width divided by 2. This value is overridden byandroid:innerRadius. Default value is 3.
Boolean. "true" if this is used as a LevelListDrawable. This should normally be "false" or your shape may not appear.
(这个属性一般是设置为fasle,下次有时间再写一篇有关LevelistDrable的学习)
②<corners>(这个节点可以设置四个角的显示半径)
Creates rounded corners for the shape. Applies only when the shape is a rectangle.(创建圆角的形状,这个节点的设置只对shape节点指定形状为矩形才生效)
attributes:(属性)
android:radius
Dimension. The radius for all corners, as a dimension value or dimension resource. This is overridden for each corner by the following attributes.
(这个尺寸是对所有的角落设置一个半径,如果同时设置下面的属性的话,这个属性会被分别覆盖掉)
android:topLeftRadius
Dimension. The radius for the top-left corner, as a dimension value or dimension resource.
android:topRightRadius
Dimension. The radius for the top-right corner, as a dimension value or dimension resource.
android:bottomLeftRadius
Dimension. The radius for the bottom-left corner, as a dimension value or dimension resource.
android:bottomRightRadius
Dimension. The radius for the bottom-right corner, as a dimension value or dimension resource.
Note: Every corner must (initially) be provided a corner radius greater than 1, or else no corners are rounded. If you want specific corners to not be rounded, a work-around is to use android:radius to set a default corner radius greater than 1, but then override each and every corner with the values you really want, providing zero ("0dp") where you don't want rounded corners.
Padding to apply to the containing View element (this pads the position of the View content, not the shape).
(填充适用于有包含视图的元素,填充的位置为被包含的视图的位置,而不是定义的shape)
attributes:
android:left
Dimension. Left padding, as a dimension value or dimension resource.
android:top
Dimension. Top padding, as a dimension value or dimension resource.
android:right
Dimension. Right padding, as a dimension value or dimension resource.
android:bottom
Dimension. Bottom padding, as a dimension value or dimension resource.
⑤<size>(大小) The size of the shape.
(定义的几何形状的大小)
attributes:
android:height
Dimension. The height of the shape, as a dimension value or dimension resource.
android:width
Dimension. The width of the shape, as a dimension value or dimension resource.
(上面分别是对高度和宽度进行设置)
Note: The shape scales to the size of the container View proportionate to the dimensions defined here, by default. When you use the shape in an ImageView, you can restrict scaling by setting the android:scaleType to "center".