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:
Let's take a 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: color specifies the fill color
Gradient: gradient
Android: startColor and android: endColor are the start and end colors respectively. ndroid: angle is the gradient angle, which 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: color stroke color.
We can also draw the stroke into a dotted line. The setting method is as follows:
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 that bottomLeftRadius is in the lower right corner, rather than in the lower left corner. This is a bit depressing, but it does not affect usage. Remember 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: