Drawable represents an abstract concept that can be drawn on a canvas.
6.1 Drawable Introduction
Drawable is often used as a background for view.
Drawable are generally defined by XML.
Drawable is an abstract class, which is the base class for all drawable objects, and each specific drawable is its subclass.
The internal width/height of the drawable is important and can be obtained by means of both getintrinsicwidth and Getintrinsicheight.
Classification of 6.2 drawable
6.2.1 Bitmapdrawable
It means a picture <bitmap/>
6.2.2 Shapedrawable
It can be understood as a graphic constructed from color, which can be either a solid color or a graphic with a gradient effect.
<shape> tags, sub-attributes android:shape= "Four options, rectangle,oval,line,ring"
Child label
<coners>, only for rectangular shape, where the angle refers to the extent of the fillet, expressed in px.
<gradient>, with the <solid> label mutually exclusive, where solid represents a solid fill, and two gradient is a gradient effect
<solid>, solid fill, android:color to specify the color of the fill in shape
<stroke>,shape's Stroke
<padding>, which represents a blank, but it does not represent a shape's white space, but a blank of the view that contains it
Size of the <size>,shape
6.2.3 layerdrawable
The corresponding XML tag is <layer-list>, which represents a hierarchical set of drawable that achieves a superimposed effect by weaving different drawable over different layers.
A layer-list can contain more than one item, and each item represents a drawable
6.2.4 statelistdrawable
The corresponding XML tag is <selector>, and also represents the Drawable collection, and each drawable corresponds to a state of view.
Common status: android:state_pressed/state_focused/state_selected/state_checked/state_enabled.
6.2.5 levellistdrawable
The corresponding XML tag is <level-list>, and each drawable has a hierarchy (Levle) concept.
Depending on the level, the levellistdrawable will switch to the corresponding drawable
6.2.6 transitiondrawable
The corresponding XML tag is <TRANSITION>, which is used to achieve the fade effect between the two drawable
6.2.7 insetdrawable
The corresponding XML tag is <INSET>, which can embed other drawable into itself, and can leave a certain interval around.
6.2.8 scaledrawable
The corresponding XML tag is <scale>, which scales the specified drawable to a certain scale according to its level.
6.2.9 clipdrawable
The corresponding XML tag is <clip>, and he can cut another drawable based on his current level.
6.3 Custom Drawable
Drawable's working principle is simple, its core is the draw method.
The drawable draw method is called to draw the view background and can be customized by overriding the Drawable draw method drawable
Draw,setalpha,setcolorfilter and getopacity are methods that must be overloaded to implement.
The sixth chapter: Android drawable