LayerDrawable
LayerDrawable is a subclass of the Android Drawable class that allows developers to stack multiple drawable resources on top of each other in a single object. Each individual drawable is referred to as a layer, and the layers are rendered in the order they are added—layer zero is drawn first, then layer one on top, and so on. Because LayerDrawable inherits from Drawable, it can be used wherever a Drawable is expected, such as in ImageView, background attributes, and layout XML.
A LayerDrawable is typically instantiated either in XML or programmatically. In XML, a <layer-list> element defines
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/outline" android:drawable="@drawable/outline" />
<item android:id="@+id/center" android:drawable="@drawable/center" />
<item android:id="@+id/foreground" android:drawable="@drawable/foreground" />
Programmatic creation involves passing an array of Drawable objects to the LayerDrawable constructor. Layers can be
LayerDrawables are useful for creating complex UI components without inflating multiple views. They simplify shading, borders,