banded background with two colors?

As others pointed out, a ninepatch would be ideal in this situation (and won’t take much memory). Working around with XML is not optimal. Here is something you can try:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:bottom="20dp">
        <shape android:shape="rectangle" >
            <size android:height="20dp" />
            <solid android:color="#ff0000" />
        </shape>
    </item>

    <item android:top="20dp">
        <shape android:shape="rectangle" >
            <size android:height="20dp" />
            <solid android:color="#0000ff" />
        </shape>
    </item>
</layer-list>

in this case your view is considered beeing 40dp high

It’s a layer list with two blocks in different colors. The problem with the XML approach is that you can’t adjust the height of the blocks to a percentage (=50%). You have to use half of the actual view size in dp. Which means you have to adjust this drawable each time you change your view height/layout. A ninepatch would adjust to this automatically.

Leave a Comment