Android Shape Usage Summary

Source: Internet
Author: User

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:shapeDefine the value of shape, which must be one of the following:"Rectangle"Matrix, which is also the default shape"Oval"Elliptic"line"A horizontal line. This shape must use the <stroke> element to define the width of this line"Ring"The properties below the ring are only used when the android:shape= "ring":Android:innerradiusSize. The radius of the inner ring. A size value (dip, and so on) or a size resource.Android:innerradiusratioFloat 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:thicknessSize. The thickness of the ring is a resource of a dimension value or dimension.Android:thicknessratioFloat 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:uselevelThe 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:radiusDimension. The radius of the fillet. Is overridden by each of the following specific fillet properties.Android:topleftradiusDimension. Top-left set the radius of the upper-left cornerAndroid:toprightradiusDimension. Top-right set the RADIUS in the upper-right cornerAndroid:bottomleftradiusDimension. Set the radius in the lower right cornerAndroid:bottomrightradiusDimension. Set the radius of the lower left corner<gradient>Specifies the gradient color for this shape.Android:angleInteger. The angle of the gradient. 0 represents from left to right. 90 represents bottom to top. Must be a multiple of 45, default is 0Android:centerxFloat. The relative x-coordinate of the gradient center, between 0 and 1.0.Android:centeryFloat. The relative y-coordinate of the gradient center, between 0 and 1.0.Android:centercolorColor. The optional color value. Based on between StartColor and EndColor.Android:endcolorColor. The end color.Android:gradientradiusFloat. The radius of the gradient. Only used in android:type= "radial"Android:startcolorColor. The starting color value.Android:typeKeyword. Gradient mode, one of the following values:"Linear"Linear gradient. This is also the default mode"Radial"Radiation gradients. StartColor is the color of the radiation center"Sweep"Scan line gradient.Android:uselevelBoolean. True if used in levellistdrawable<padding>The distance between the content and the view boundaryAndroid:leftDimension. The left padding distance.Android:topDimension. The top padding distance.Android:rightDimension. The right padding distance.Android:bottomDimension. Bottom padding distance.<size>The size of this shape.Android:heightDimension. The height of this shape.Android:widthDimension.     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 shapeAndroid:colorColor. 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:widthDimension. The thickness of the stroke.Android:colorColor. Color of strokesAndroid:dashgapDimension. Each line is drawn at a distance of how much. Only valid if the Android:dashwidth is set.Android:dashwidthDimension. 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 spaces, 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>

Android Shape Usage Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.