In the development of Android programs, we often use shape to define a variety of shapes.
Shape is used for setting shapes, can be used in selector,layout and so on, there are 6 sub-tags, the properties are as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:shape= "Rectangle" ><!--Set shapes-<!--rounded corners-<corners android:radius= "9DP" android:topleftradius= "2DP" android:toprightradius= "2DP" android:bottomleftradius= "2DP" android:b ottomrightradius= "2DP"/><!--set Fillet radius-<!--gradient--<gradient android:startcolor= @andr Oid:color/white "android:centercolor=" @android: Color/black "android:endcolor=" @android: Color/black "a Ndroid:uselevel= "true" android:angle= "android:type=" radial "android:centerx=" 0 "Android:ce ntery= "0" android:gradientradius= "/>" <!--interval-<padding android:left= "2DP" android:top= "2DP" android:right= "2DP" android:bottom= "2DP"/><!--All directions--<!--size--&G T <size android:width= "50DP" android:height= "50DP"/><!--width and height-<!--filled-in < ; Solid AndroidOid:color= "@android: Color/white"/><!--filled colors-<!--strokes-<stroke android:width= "2DP "Android:color=" @android: Color/black "android:dashwidth=" 1DP "android:dashgap=" 2DP "/> </sha Pe>
Fill: Sets the color of the fill
interval: sets the interval in four directions
Size: set Size
fillet: set five properties at the same time, the RADIUS attribute is invalid
android:radius= "20DP" sets the radius of Four Corners
android:topleftradius= "20DP" sets the radius of the upper-left corner
Android:toprightradius= "20DP" set the radius of the upper-right corner
android:bottomleftradius= "20DP" setting the radius of the lower right corner
Android:bottomrightradius= "20DP" set the radius of the lower left corner
strokes:dashwidth and Dashgap properties, as long as one is set to 0DP, the border is the implementation border
Android:width= "20DP" sets the width of the edge
Android:color= "@android: Color/black" Sets the color of edges
Android:dashwidth= "2DP" to set the width of the dashed line
android:dashgap= "20DP" sets the interval width of the dashed line
Gradients: when the fill color is set, there is no gradient effect. The value of the angle must be a multiple of 45 (including 0), only valid in type= "linear", or it will be an error. Android:uselevel This attribute does not know what is the use.
Angle the starting point of the corresponding value
Assume that the above code is in the XML file under Drawable button.xml.
[HTML]View Plaincopy
- <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="Http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/button"
- android:text="Testshapebutton" />
- </relativelayout>
Specify background directly as Button.xml under the Drawable folder.
The program runs as follows:
Use of Android shape (RPM)