.
The use of the original shape in the Android
Ckf1122 attention 2011.03.21 read 126293
Himself in the aspect of art has always been more idiot, what a mess for some color very headache, but it is often involved in Android programming, can't, only crustily skin of head,
Android shape to define the controls is often used in some of the display attributes, today to see the use of some of the shape, the shape have roughly understanding, make a little summary:
Look at the code below:
Android: endColor="# FFFFFF"
Android: Angle="270"/& gt;
Android: color="# DCDCDC"/& gt;
Android: top="10 dp"
Android: right="10 dp"
Android: bottom="10 dp/& gt;"
Solid: solid, is the meaning of
Android: the color of the color specified filling
Gradient: the gradient
Android: startColor and android: endColor color start and end, respectively, ndroid: Angle is the gradient Angle, must be 45 integer times,
Another gradient default mode for android: type="linear", namely the linear gradient, you can specify gradient as the radial gradient, android: type="radial", radial gradient android: you need to specify the radius gradientRadius="50",
Stroke: the stroke
Android: width="2 dp" stroke width, android: color the color of the stroke,
We can also get the stroke into the dotted line form, set up the way for:
Android: dashWidth="5 dp"
Android: dashGap="3 dp"
The android: dashWidth said '-' a horizontal line width, android: dashGap separated by distance between said,
Corners: rounded
Android: the radius of the radian of Angle, the larger the value Angle of the circle,
We can also set your four corners into different point of view, the method is:
Android: bottomLeftRadius="20 dp" at the bottom right
Left upper corner of the android: topLeftRadius="1 dp"
Android: bottomRightRadius="0 dp" lower left
/& gt;
There's a place to need to pay attention to, bottomLeftRadius is the lower right corner, rather than the lower left corner, this is a bit depressed, but does not affect the use, remember don't make a mistake,
And online to see some people say that is set to 0 dp is invalid, but I can be found in the test, I am using is 2.2, may fix this problem, it can only be set to 1 if invalid dp,
Padding: interval
This is needless to say, is often used in the XML layout file,
This is general, the following is a concrete example: use in the Selector as background of the Button, defines the general condition of buttons respectively obtain when the focus state and press state, specific code is as follows:
The main XML:
Android: layout_height="wrap_content"
Android: text="TestShapeButton"
Android: background="@ drawable/button_selector"
/& gt;
Button_selector. XML:
<? The XML version="1.0" encoding="utf-8"?>
Android: endColor="# FFFFFF"
Android: type="radial"
Android: gradientRadius="50"/& gt;
Android: color="# DCDCDC"
Android: dashWidth="5 dp"
Android: dashGap="3 dp/& gt;"
Android: top="10 dp"
Android: right="10 dp"
Android: bottom="10 dp/& gt;"
Android: endColor="# ffc2b7"
Android: Angle="270"/& gt;
Android: color="# DCDCDC"/& gt;
Android: top="10 dp"
Android: right="10 dp"
Android: bottom="10 dp/& gt;"
Android: color="# fad3cf"/& gt;
Android: bottomLeftRadius="5 dp"
Android: topLeftRadius="0 dp"
Android: bottomRightRadius="0 dp"
/& gt;
Android: top="10 dp"
Android: right="10 dp"
Android: bottom="10 dp/& gt;"
Running effect is as follows:
General condition:
Get the focus state:
Press the status:
Copyright owned by the author, from the original work of 51 cto blog author ckf1122 for reprint, please indicate the source, otherwise will be investigated for legal responsibility
ckf1122