2011-03-21 20:08:19Tags: Android shape Original Work in mobile development, which can be reproduced. During reprinting, be sure to mark it as a hyperlinkArticleOriginal source, author information, and this statement. Otherwise, legal liability will be held. Http://kofi1122.blog.51cto.com/2815761/521605
I have always been an idiot in the art field, and it is a headache for some messy colors, but this is often involved in Android programming, there is no way, only a hard head.
In Android, shape is often used to define some Display Properties of the control. Today I have read some shapes and have a general understanding of shape. I would like to make a summary:
First look at the following Code :
<Shape>
<! -- Solid -->
<Solid Android: color = "# ff9d77"/>
<! -- Gradient -->
<Gradient
Android: startcolor = "# ff8c00"
Android: endcolor = "# ffffff"
Android: angle = "270" type = "parmname" text = "parmname"/>
<! -- Stroke -->
<Stroke
Android: width = "2dp"
Android: color = "# dcdcdc"/>
<! -- Rounded corner -->
<Corners
Android: radius = "2dp"/>
<Padding
Android: Left = "10dp"
Android: Top = "10dp"
Android: Right = "10dp"
Android: Bottom = "10dp"/>
</Shape>
Solid: solid, indicating Filling
Android: ColorFill color
Gradient: Gradient
Android: startcolor and Android: endcolor are the start and end colors respectively. ndroid: angle is the gradient angle,Must be an integer multiple of 45.
In addition, the default gradient mode is Android: TYPE = "linear", that is, linear gradient. You can specify the gradient as a radial gradient, Android: TYPE = "RADIAL", and the radius must be specified for the radial gradient Android: gradientradius = "50 ".
stroke: stroke
Android: width = "2dp" stroke width, Android: the color of the stroke.
You can also set the stroke to a dotted line:
Android: dashwidth = "5dp"
Android: dashgap = "3dp"
Android: dashwidth indicates the width of a horizontal line like '-', and Android: dashgap indicates the distance between them.
Corners: rounded corner
Android: radius is the Radian of an angle. The larger the value is, the closer the angle is.
We can also set the four angles to different angles:
<Corners
Android: toprightradius = "20dp" upper right corner
Android: bottomleftradius = "20dp" bottom right corner
Android: topleftradius = "1dp" upper left corner
Android: bottomrightradius = "0dp" lower left corner
/>
Note the following,Bottomleftradius is lower rightNot the lower left corner,This is a bit depressing, but it does not affect usage. Remember not to make a mistake.
Some people on the Internet said that setting 0dp is invalid, but I found it works during the test. I used 2.2. Maybe this problem has been fixed, if it is invalid, it can only be set to 1dp.
Padding: interval
This is not much to mention. It is often used in XML layout files.
In general, the following is a specific example: Used as the background of the button in selector, which defines the general status of the button, the obtained focus status, and the status when the button is pressed, respectively, 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"?>
<Selector
Xmlns: Android = "http://schemas.android.com/apk/res/android">
<Item Android: state_pressed = "true">
<Shape>
<! -- Gradient -->
<Gradient
Android: startcolor = "# ff8c00"
Android: endcolor = "# ffffff"
Android: TYPE = "RADIAL"
Android: gradientradius = "50"/>
<! -- Stroke -->
<Stroke
Android: width = "2dp"
Android: color = "# dcdcdc"
Android: dashwidth = "5dp"
Android: dashgap = "3dp"/>
<! -- Rounded corner -->
<Corners
Android: radius = "2dp"/>
<Padding
Android: Left = "10dp"
Android: Top = "10dp"
Android: Right = "10dp"
Android: Bottom = "10dp"/>
</Shape>
</Item>
<Item Android: state_focused = "true">
<Shape>
<Gradient
Android: startcolor = "# ffc2b7"
Android: endcolor = "# ffc2b7"
Android: angle = "270" type = "parmname" text = "parmname"/>
<Stroke
Android: width = "2dp"
Android: color = "# dcdcdc"/>
<Corners
Android: radius = "2dp"/>
<Padding
Android: Left = "10dp"
Android: Top = "10dp"
Android: Right = "10dp"
Android: Bottom = "10dp"/>
</Shape>
</Item>
<Item>
<Shape>
<Solid Android: color = "# ff9d77"/>
<Stroke
Android: width = "2dp"
Android: color = "# fad3cf"/>
<Corners
Android: toprightradius = "5dp"
Android: bottomleftradius = "5dp"
Android: topleftradius = "0dp"
Android: bottomrightradius = "0dp"
/>
<Padding
Android: Left = "10dp"
Android: Top = "10dp"
Android: Right = "10dp"
Android: Bottom = "10dp"/>
</Shape>
</Item>
</Selector>
The running effect is as follows:
General status:
Get focus status:
Press status:
This article is from the "Kofi" blog, please be sure to keep this source http://kofi1122.blog.51cto.com/2815761/521605