<Shape> <!– Solid –> <SolidAndroid:color= "#ff9d77 ″/><!– Gradient –> <GradientAndroid:startcolor= "#ff8c00 ″Android:endcolor= "#FFFFFF"Android:angle= "270″/> <!– Stroke –> <StrokeAndroid:width= "2DP"Android:color= "#dcdcdc"/> <!– Rounded Corners –> <CornersAndroid:radius= "2DP"/> <paddingAndroid:left= "10DP"Android:top= "10DP"Android:right= "10DP"Android:bottom= "10DP"/> </Shape>
Solid: filled is the meaning of filling
android:color Specifies the color of the fill
gradient: gradient
android:startcolor and Android:endcoloR are start and end colors respectively,ndroid:angle is the gradient angle and must be an integer multiple of 45.
In addition, the default mode of the gradient is android:type= "Linear", that is, linear gradient, you can specify the gradient to radial gradient,android:type= "Radial", radial gradient needs to specify the radius Android:gradientradius= "50″.
Stroke: Stroke
android:width= width of the "2DP" Stroke,android:color The color of the stroke.
We can also make the stroke into a dashed form, set in the following way:
android:dashwidth= "5DP"
android:dashgap= "3DP"
Where android:dashwidth represents the width of a horizontal line such as '-', android:dashgap represents the distance between them.
Corners: Rounded corners
The Android:radius is the radian of the angle, and the larger the value the greater the rounded.
We can also set the four angles to different angles by:
< Corners Android:toprightradius = "20DP" Upper right corner android:bottomleftradius= "20DP" lower right corner android:topleftradius= " 1DP " Upper left corner android:bottomrightradius=" 0DP " />
Here is a place to pay attention, Bottomleftradius is the lower right corner, not the lower left corner, this is a bit depressed, but do not affect the use, remember not to make a mistake on the line.
There are also online to see someone said set to 0DP invalid, but I found in the test is OK, I use 2.2, may fix the problem, if it is invalid, it can only be set to 1DP.
padding: Interval
This is not much to say, XML layout files are often used.
In general, the following is a specific example of use: using the background as a button in selector, define the normal state of the buttons, the state of the focus and the state of the press, the code is as follows:
Main.xml:
< Button Android:layout_width = "Wrap_content" Android:layout_height = "Wrap_content" Android:text = "Testshapebutton" Android:background = "@drawable/button_selector" />
Button_selector.xml:
<?XML version= "1.0″encoding=" Utf-8″?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android" ><item android:state_pressed= "true"> <Shape> <!– Gradients –> <GradientAndroid:startcolor= "#ff8c00 ″Android:endcolor= "#FFFFFF"Android:type= "Radial"Android:gradientradius= "50″/> <!– Stroke –> <StrokeAndroid:width= "2DP"Android:color= "#dcdcdc"Android:dashwidth= "5DP"Android:dashgap= "3DP"/> <!– Rounded Corners –> <CornersAndroid:radius= "2DP"/> <paddingAndroid:left= "10DP"Android:top= "10DP"Android:right= "10DP"Android:bottom= "10DP"/> </Shape> </Item> <Itemandroid:state_focused= "true"> <Shape> <GradientAndroid:startcolor= "#ffc2b7 ″Android:endcolor= "#ffc2b7 ″Android:angle= "270″/> <StrokeAndroid:width= "2DP"Android:color= "#dcdcdc"/> <CornersAndroid:radius= "2DP"/> <paddingAndroid:left= "10DP"Android:top= "10DP"Android:right= "10DP"Android:bottom= "10DP"/> </Shape> </Item> <Item> <Shape> <SolidAndroid:color= "#ff9d77 ″/><stroke android:width= "2DP"Android:color= "#fad3cf"/> <CornersAndroid:toprightradius= "5DP"Android:bottomleftradius= "5DP"Android:topleftradius= "0DP"Android:bottomrightradius= "0DP"/> <paddingAndroid:left= "10DP"Android:top= "10DP"Android:right= "10DP"Android:bottom= "10DP"/> </Shape> </Item></selector>
Operating effects such as:
General Status:
Get Focus Status:
Press the Status:
This article transferred to: http://kofi1122.blog.51cto.com/2815761/521605
Properties of shape in Android