Android Making a drawable XML composed of several bitmaps

android, drawable, xml

Solution

Unfortunately I can't really test this right now, but I believe you can pull this off with a LayerListDrawable like this:

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap
            android:src="@drawable/diamond_metal"
            android:tileMode="repeat" />
    </item>

    <item android:right="10dp" android:bottom="10dp">
        <bitmap
            android:src="@drawable/screw"
            android:gravity="bottom|right" />
    </item>

    <item android:left="10dp" android:bottom="10dp">
        <bitmap
            android:src="@drawable/screw"
            android:gravity="bottom|left" />
    </item>

    <item android:top="10dp" android:left="10dp">
        <bitmap
            android:src="@drawable/screw"
            android:gravity="top|left" />
    </item>

    <item android:top="10dp" android:right="10dp">
        <bitmap
            android:src="@drawable/screw"
            android:gravity="top|right" />
    </item>
</layer-list>

Replacing the 10dp values with whatever inset you need for the screws.

Problem

I have this background for several `LinearLayout`s throughout my app: ``` android:background="@drawable/metal_plate" ``` drawable\metal_plate.xml: ``` <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/diamond_metal" android:tileMode="repeat" android:dither="true"> </bitmap> ``` I would like to place 4 bitmaps of screws in the 4 corners of the metal plate. I use the metal plate in several places, so I prefer to define it as a single drawable than having to place the 4 screws on every ocasion with a `RelativeLayout`. Is it possible to define an XML in the drawable folder to combine the tiled metal plate and the 4 screws?

Original source