Unlike the one who said, there are also width and height attributes for <item> . Thanks to @Entreco for posting a demonstration of this.
android:width and android:height for Drawable similar to android:layout_width and android:layout_height for View c, unlike they cannot be set to either match_parent or wrap_content , but you can achieve the same match_parent behavior by setting attribute android:gravity value left|right or start|end (to match the parent width) or top|bottom (to match the parent height).
Unfortunately, these attributes are only available after API 23.
However, given the above method, which I suggested instead of match_parent and that the android:width and android:height attributes are available for the <size> element (which should be placed inside the <shape> ) without any API restrictions, you can use a simple workaround :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <size android:width="152dp" android:height="152dp"/> <solid android:color="#00FFFFFF"/> </shape> </item> <item> <bitmap android:gravity="left|right|top|bottom" android:src="@mipmap/ic_launcher"/> </item> </layer-list>
The above solution takes advantage of the size of <item> (with transparent <shape> ) and non-standard (with <bitmap> ), for which android:gravity set to left|top|right|bottom to match both parent dimensions. Thus, the actual size of the <bitmap> will be determined by the size of the unique size of the <item> in the same parent element.
EDIT:
Thanks to @Emil S, who noticed that the above solution will not work as the background of the window. It only works as a background or foreground of any kind. I donβt know the specific reason for this strange behavior, but I can assume that while the system creates a window with the background specified in the android:windowBackground , the layout does not work, since the process has not been started yet. So Android will eventually rasterize the stretchable image to the screen size and stretch it to fill the whole window, I think. This explains how this could happen.
EDIT:
@ Joao Carlos pointed out that my solution will not work (because it will cause circular inheritance) when using the adaptive icon (icons made by background and foreground that support vector graphics). However, his point of view is pointless, since adaptive icons require API 26: you can use android:width and android:height directly on the splash screen or something like that (they just need API 23).
Therefore, in order for something to work in any version of Android, you need to distinguish between two drawn elements, the first for the API & lt; 23, using the solution I posted, and the last for the API> = 23, using two attributes, as I said at the beginning of my post.