Drawable Resource
A drawable resource is a common concept in plotting and can be drawn on the screen. You can retrieve it using the getdrawable (INT) method in APIs, or use it using Android: drawable, Android: icon, and other attributes in other XML resources. There are multiple types of drawable in Android.
Bitmap File: A Map File (.png, .jpg, or .gif) to generate a bitmapdrawable object.
Nine-patch file: generate a ninepatchdrawable object based on a PNG Image (.9.png) that can automatically adapt to large and small sizes.
Layer list: This drawable is used to manage one or more drawable arrays. Since it is an array, it is not difficult to understand that the element with the largest index value will be painted in the highest part. A layerdrawable object will be generated.
State List: This is an XML file used to reference different bitmap images in different States (for example, when a button control is pressed to display different images). Generate a statelistdrawable object.
Level list: an XML file that defines a drawable that can be used to manage several drawable that can be replaced. Each of them will be assigned a maximum value. A levellistdrawable will be generated.
Transition drawable: an XML file that defines a drawable that can be used for two images to form a gradient transition effect to generate a transitiondrawable object
Inset drawable: an XML file that defines a drawable and is inserted to another drawable at a specified distance. this can be used when a view <View> object requires a background image smaller than its actual border.
Clip drawable: an XML file that defines a drawable and generates a clipdrawable object based on the current aligning value for corresponding stretching.
Scale drawable: an XML file that defines a drawable and generates a scaledrawable object based on the current aligning value.
Shape drawable: defines a ry that contains color and gradient through an XML file, and generates a shapedrawable object.
Animationdrawable: You can also create an animationdrawable object.
Color drawable: in XML, a color resource <Color Resource> can also be used as a drawable. For example, when creating a State List drawable, You can reference a color resource for the Android: drawable attribute (android:drawable="@color/green"
)
Drawable resources are all files stored in the Res/drawable directory. Of course, in an object-oriented language, it will eventually become an object. In Android, The drawable class represents such resources. Below is the inheritance relationship between drawable and subclass.
Several common static methods in drawable can be used to create a drawable object from a file.