Shape drawable in layer-list rendered incorrectly for APIs below 23
First of all, I'd like to thank @pskink for helping me to analyse the problem :)
The xml in the question worked for API level 23+, because
it is possible to set width and height right within the "item" tag
like @android developer states in this SO post
It did not work for lower versions, because there one needs to set width
and height
attributes for a ShapeDrawable
using the size
tag.
I suppose Android needs the size to figure out how to scale the drawable (-> aspect ratio!) while taking into account the insets (top, left, right, bottom).
And as is sometimes the case with malformed (for a specific API level) xml, Android failed silently and simply did not draw the shape.
So the solution is:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:width="80px" android:height="80px" android:top="0px" android:left="0px" android:right="0px" android:bottom="0px"> <shape android:shape="rectangle"> <solid android:color="@color/deep_orange"/> </shape> </item> <item android:width="60px" android:height="60px" android:top="10px" android:left="10px" android:right="10px" android:bottom="10px"> <shape android:shape="oval"> <solid android:color="@color/light_yellow"/> <size android:height="60px" android:width="60px"/> </shape> </item></layer-list>