Detailed explanation and example of Android custom shadow effect
Detailed explanation and example of Android custom shadow effect
In Android 5. X, Google has added two attributes Android: elevation = "" and Android: translationz = "", which correspond to the height change in the vertical direction. The system will automatically increase the shadow effect.
Add Android: elevation = "8dp" in tablayout. The effect is as follows:
Custom shadow effects
The shadow effect is as follows:
principle
Achieved by covering
It is divided into two layers: foreground layer and background layer
Foreground layer: set a green rectangular area
Background layer: a rectangle filled with excessive color from black to green. Choose "green" here because the above is also a green.
Create XML in RES / drawable. The XML code is as follows:
Tip: the notes are for the convenience of readers, so if you report an error, delete the notes.
Then set the Android: background = "@ drawable / shadow of tablayout_ bg”
Layerdrawable object
I believe you have a better understanding of shapedrawable. Here we talk about the less used layerdrawable. If you feel it necessary to talk about shapedrawable, you can give feedback in the comments.
Layerdrawable can contain a drawable array, and the system will draw in the order of the array of these drawable objects.
Define the root element of the layerdrawable object XML file as < layer list > < / layer list. This element can contain multiple < item > < / item > elements, which can specify the following attributes:
Thank you for reading, hope to help you, thank you for your support to this site!