In Android development, the use of custom resource files, which is very important is the shape file, shape file can be used to define any shape, often used to do background color.
The shape file is actually also. xml, whose root element is shape. The meanings of the various elements and attributes in the shape file are described in detail below.
root element <shape> Specify basic shape
The Shape property specifies the base shape, the allowable values are: Rectangle (Rectangle), oval (ellipse), line (lines), Ring (ring). The default value is a rectangle, and the following code defines a rectangle:
<?xml version= "1.0" encoding= "Utf-8"? ><shape android:shape= "Rectangle" xmlns:android= "http// Schemas.android.com/apk/res/android "></shape>
The Visible property sets whether the shape is initially visible.
The following properties are available only when a shape is defined as a ring:
Innerradius specifies the radius of the inner ring (that is, the hollow hole) and receives the dimension type.
Innerradiusratio is floating point, which represents the radius of the inner ring at the width ratio of the ring, for example, if android:innerradiusratio, which means that the inner ring radius is equal to the width of the ring divided by 5, the value can be overwritten and the default is 9.
Thickness the thickness of the specified ring, the type is dimension.
Thicknessratio is also floating point, with the width ratio of the ring representing the thickness of the ring, for example, if the value is "2", then the thickness of the ring is equal to the width of the ring divided by 2. This value can be overridden by android:thickness, and the default value is 3.
For Uselevel please go to the next section <gradient>.
<gradient> set a gradient fill
StartColor, Centercolor, EndColor sets the start and end color of the gradient, which allows you to set the gradient two times.
Angle sets the angle of the gradient, which is valid only if the gradient type is a linear gradient . The default 0 value is horizontal to right, other angles are rotated counterclockwise, for example set to 90 is bottom-up, set to 270 top-down, and so on. Note: Must be a multiple of 45.
Type sets the gradient type, which defaults to linear (linear gradient), and if set to radial (radial gradient), you must also set the Gradientradius property, which specifies the gradient radius, Note: This radius is not dimension, do not accept DP and other units, can only set the number. In addition, you can set a more interesting way: sweep (scan gradient). See the effect of three gradient modes.
650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M01/48/80/ Wkiom1qjivhasvnvaabjyjeczmq405.jpg "style=" width:120px;height:35px "title=" linear "width=" height= "0" hspace= "0" vspace= "0" alt= "wkiom1qjivhasvnvaabjyjeczmq405.jpg"/>650) this.width=650; "src="/HTTP// S3.51cto.com/wyfs02/m00/48/82/wkiol1qjivejpiymaaa9ujm6fyi858.jpg "style=" width:120px;height:35px; "title=" Radial "Width=" height= "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" wkiol1qjivejpiymaaa9ujm6fyi858.jpg "/>650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/48/80/wKiom1QJIVLwonO6AABGUVLu89w952.jpg "style=" width : 120px;height:34px; "title=" Sweep "width=" + "height=" border= "0" hspace= "0" vspace= "0" alt= " Wkiom1qjivlwono6aabguvlu89w952.jpg "/>
CenterX, centery Two properties are used to set the center point position of the gradient, only valid if the gradient type is a radial gradient , the type is fractional or decimal, and the dimension is not accepted. The default value is 0.5, the valid value is 0.0~1.0, and the gradient is not visible after the range is exceeded.
The Uselevel property is not typically used. This property is used to specify whether the shape is to be used as a levellistdrawable, and the default value is False.
The following code defines a linear up-down gradient:
<gradient android:startcolor= "#67CC24" android:endcolor= "#3E9010" android:angle= "/>"
<solid> Set Solid color fills
This element itself has nothing to say, since it is a solid color fill, only a color attribute.
Note: If the same file specifies both a gradient and a solid fill, then the order will overwrite the previous setting!
<size> Specify size
Use width and height to set the width height, respectively, and type dimension.
Note: Theshape file is also scaled to its container size when used by default, even if size is specified. if used in ImageView, you can use Android:scaletype to scale the limit.
<stroke> Strokes
When the shape you define is line, this property is a required option to set the style of the line. The element acts as a stroke when the shape is a different shape.
width Specifies the bounding rectangle (Dimension), color specifies the border colour, and only the color type is accepted.
We can also set a dashed border: use Dashgap to set the interval between dashes, dashwidth set the length of each dashed line '-' (why doesn't Google call this length?). I don't know, either. the dashed effect takes effect only if both properties are set .
The following code defines a dashed blue border:
<stroke android:color= "#0000FF" android:width= "5DP" android:dashgap= "3DP" android:dashwidth= "10DP"/>
<corners> Set rounded corners
This element takes effect only if the shape is a rectangle. Topleftradius, Toprightradius, Bottomleftradius, Bottomrightradius four properties set Four Corners respectively, radius is set uniformly (Four corners are the same). The following code sets four identical rounded corners:
<corners android:radius= "10DP"/>
<padding> Setting margins
Refer to attributes such as android:layout_paddingleft for the meaning of this element. There are four directions left, right, top, bottom can be set, but no uniform settings are provided.
All of the available elements and attributes of the shape file are described above, but it is more useful to use more than just a good shape. If there is any mistake or improper description, you are welcome to criticize.
This article is from the "Flying Cat" blog, be sure to keep this source http://flyingcat2013.blog.51cto.com/7061638/1549077
An explanation of the Android shape file properties