Gradient angle android shape of understanding
First, a clear shape belong drawable, Chinese literal translation is drawable (familiar things are objects). So in the file folder shape drawable files.
Second hands to create shape files.
Create a shape file
- 1, right-drawable folder, select the secondary menu, drawable resource file
- 2, enter the file name, file generation
- 3, pay attention to where the file is select the root tag
- 4, can be manually changed shape
- 5, sub-label shape, not many
On a piece of code
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/dark_blue"
android:endColor="@color/purple"
android:angle="-135"
/>
</shape>
This code is very short, first pointed out the shape of the shape, rectangle, and then put this rectangle to make a gradient color, the color began to mean the leftmost color, the color of the object relative to the end of this rightmost color. If the angle is set to 0, you will get such a picture:
Try a few angles, I think I find the law change the gradient angle. It is a positive counter-clockwise direction, the angle is greater than zero, that is, counter-clockwise. This just like our normal understanding of the same. A counter-clockwise angle is positive. Logical normal, this design is very reasonable.
For example, when the angle is 90, it should be startColor rotated 90 degrees counterclockwise, that is, startColor came bottom position, you can experiment to test. Angle is set to 90, the image:
This and our previous knowledge connected. nice! no previous knowledge learned in prison, and now I feel very embarrassed! oo!
About drawable more knowledge can watch the official website direct document, points me to get away