Detailed explanation of shape usage in Android
Shapedrawable is a very common drawable, which can be understood as a figure constructed by color. It can be either a solid color figure or a figure with gradient effect. Shapedrawable syntax is slightly complex, as shown below:
•Android: shape
• there are four options, rectangle, oval, line and ring. The default is rectangle. Note that line and ring need to specify the width and color of the line through labels, otherwise the expected effect cannot be achieved
• first, let's talk about the most commonly used rectangle. Generally, a background drawable is set on the button or font. The general setting effect is a square or a shape with radians on both sides.
· the first case is to set a rectangular background
Set the width and height of the rectangle by setting the size, * it should be explained here that setting the width and height of the size here is useless in the final display size, that is, when you set the background in a control, the shape will be stretched or reduced to the size of the view* The solid property sets the background color inside the rectangle.
Set the background color to gradient
design sketch:
The default type here is linear. There are two other attributes to choose from: radial gradient and sweep gradient. Generally, the most commonly used one is linear gradient. There are several other attributes that are useless but easy to understand
Android: Angle -- gradient angle. The default value is 0. Its value must be a multiple of 45. 0 means from left to right, and 90 means from bottom to top.
Android: centerx -- abscissa of the center point of the gradient
Android: Center -- ordinate of the center point of the gradient
Android: gradientradiu -- gradient radius, valid only when Android: type = "radial"
• next, let's talk about the rectangular background with rounded corners
· in fact, you only need to set the properties of corners.
· detailed description
· Android: radius - set the same angle for the four corners, with lower priority, which will be overwritten by the other four attributes
Android: bottomleftradius -- sets the angle of the lower left corner
Android: bottomrightradius -- sets the angle of the lower right corner
Android: topleftradius -- sets the angle of the upper left corner
Android: toprightradius -- sets the angle of the upper right corner
The next step is how to draw a hollow background
The renderings are as follows
Of course, you can also set gradient colors freely, but generally they are solid colors.
· it can also be set as dotted line here
Well, in fact, the things inside are very simple. Just summarize them. I hope you are happy with it.