Today, with shape, there are a lot of properties here, and here I'm documenting the use of each attribute and what it means.
<?XML version= "1.0" encoding= "Utf-8"?> <Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape=["Rectangle"| "Oval" | "Line" | "Ring"]> <CornersAndroid:radius= "integer"Android:topleftradius= "integer"Android:toprightradius= "integer"Android:bottomleftradius= "integer"Android:bottomrightradius= "integer" /> <GradientAndroid:angle= "integer"Android:centerx= "integer"Android:centery= "integer"Android:centercolor= "integer"Android:endcolor= "Color"Android:gradientradius= "integer"Android:startcolor= "Color"Android:type=["Linear"| "Radial" | "Sweep"] android:uselevel=["true"| "False"]/> <paddingAndroid:left= "integer"Android:top= "integer"Android:right= "integer"Android:bottom= "integer" /> <sizeAndroid:width= "integer"Android:height= "integer" /> <SolidAndroid:color= "Color" /> <StrokeAndroid:width= "integer"Android:color= "Color"Android:dashwidth= "integer"Android:dashgap= "integer" /> </Shape>
The above paragraph is the format used by shape to see how to use:
-
-
<shape>
-
- Define this as a gradientdrawable, which must be the root element.
-
-
Android:shape
-
- Define the value of shape, which must be one of the following:
-
- The "Rectangle" matrix, which is also the default shape
Oval Ellipse
"Line" A level of straight lines. This shape must use the <stroke> element to define the width of this line
-
- "Ring" ring
-
-
- The following properties are used only when android:shape= "ring":
Android:innerradius
Size. The radius of the inner ring. A size value (dip, and so on) or a size resource.
Android:innerradiusratio
Float type. This value represents the scale of the inner ring, for example, if Android:innerradiusratio = "5", then the inner radius is equal to the width of the ring divided by 5. This value will be rewritten by Android:innerradius. The default value is 9.
Android:thickness
Size. The thickness of the ring is a resource of a dimension value or dimension.
Android:thicknessratio
Float type. The ratio of thickness. For example, if you android:thicknessratio= "2", then the thickness is equal to the width of the ring divided by 2. This value is overridden by Android:innerradius, and the default value is 3.
Android:uselevel
The Boolean type. If used in levellistdrawable, then it is true. False if it usually does not appear.
-
-
-
<corners>
-
- Creates a fillet for shape, only used when shape is rectangle.
-
- Android:radius
Dimension. The radius of the fillet. Is overridden by each of the following specific fillet properties.
Android:topleftradius
Dimension. Top-left set the radius of the upper-left corner
Android:toprightradius
Dimension. Top-right set the RADIUS in the upper-right corner
Android:bottomleftradius
Dimension. Set the radius in the lower right corner
Android:bottomrightradius
Dimension. Set the radius of the lower left corner
-
-
-
<gradient>
-
- Specifies the gradient color for this shape.
-
- Android:angle
Integer. The angle of the gradient. 0 represents from left to right. 90 represents bottom to top. Must be a multiple of 45, default is 0
Android:centerx
Float. The relative x-coordinate of the gradient center, between 0 and 1.0.
Android:centery
Float. The relative y-coordinate of the gradient center, between 0 and 1.0.
Android:centercolor
Color. The optional color value. Based on between StartColor and EndColor.
Android:endcolor
Color. The end color.
Android:gradientradius
Float. The radius of the gradient. Only used in android:type= "radial"
Android:startcolor
Color. The starting color value.
Android:type
Keyword. Gradient mode, one of the following values:
-
- "Linear" linear gradient. This is also the default mode
"Radial" radiation gradient. StartColor is the color of the radiation center
"Sweep" scan line gradient.
-
- Android:uselevel
Boolean. True if used in levellistdrawable
-
-
-
<padding>
The distance between the content and the view boundary
Android:left
Dimension. The left padding distance.
-
- Android:top
Dimension. The top padding distance.
Android:right
Dimension. The right padding distance.
-
- Android:bottom
Dimension. Bottom padding distance.
-
-
<size>
The size of this shape.
Android:height
Dimension. The height of this shape.
Android:width
Dimension. The width of this shape.
Note: By default, this shape is scaled to be proportional to the size of the container in which he is located. When you use this shape in a imageview, you can use android:scaletype= "center" to limit this scaling.
-
-
-
<solid>
Fill the solid color of this shape
Android:color
Color. Color value, hexadecimal number, or a color resource
-
-
<stroke>
This shape uses a stroke that, when android:shape= "line", must be set to change the element.
Android:width
Dimension. The thickness of the stroke.
Android:color
Color. Color of strokes
Android:dashgap
Dimension. Each line is drawn at a distance of how much. Only valid if the Android:dashwidth is set.
Android:dashwidth
Dimension. The length of one line per draw. Only valid if the ANDROID:DASHGAP is set.
android:dashgap and android:dashwidth set this line to be dashed , where android:dashwidth denotes '-' The width of such a dash, Android:dashgap represents the distance between the partitions,
-
-
- Use someone else's section of code:
-
- Button_bg.xml
-
<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android" > <!--Fill - <SolidAndroid:color= "#ff9d77" /> <!--defines the color value of the fill - <!--Strokes - <StrokeAndroid:width= "2DP"Android:color= "#fad3cf" /> <!--defines the width of the stroke and the color value of the stroke - <!--Rounded Corners - <CornersAndroid:bottomleftradius= "5DP"Android:bottomrightradius= "5DP"Android:topleftradius= "5DP"Android:toprightradius= "5DP" /> <!--set the radius of Four Corners - <!--interval - <paddingAndroid:bottom= "10DP"Android:left= "10DP"Android:right= "10DP"Android:top= "10DP" /> <!--set the interval for each direction -</Shape>
The contents of Button_pressed_bg.xml are as follows:
<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android" > <!--Gradient - <GradientAndroid:endcolor= "#FFFFFF"Android:gradientradius= " the"Android:startcolor= "#ff8c00"Android:type= "Radial" /> <!--Strokes - <StrokeAndroid:dashgap= "3DP"Android:dashwidth= "5DP"Android:width= "2DP"Android:color= "#dcdcdc" /> <!--Rounded Corners - <CornersAndroid:radius= "5DP" /> <!--interval - <paddingAndroid:bottom= "10DP"Android:left= "10DP"Android:right= "10DP"Android:top= "10DP" /></Shape>
How to use, look at the following code:
<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android"> <Itemandroid:drawable= "@drawable/button_pressed_bg"android:state_pressed= "true"></Item> <Itemandroid:drawable= "@drawable/button_bg"></Item></selector>
That's it.
Android Shape Usage Summary