Question

What I wanted was while background with red part on the left. Something like this. enter image description here

I tried many things (is there any WYSIWIG editor? I think I ran this hundreds of times.) Specifying width like in the following article did not work. how to specify width and height of a drawable item

The following article only tells me that I cannot use percentage, now how to apply width. Android Drawable: Specifying shape width in percent in the XML file?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>

            <shape>
                <solid 
                android:color="#FFFFFFFF"/>
            </shape>

    </item>
    <item>

            <shape android:shape="rectangle">
                <solid android:color="#55FF0000" />
                <size android:width="100px" />
            </shape>

    </item>

</layer-list>
Was it helpful?

Solution

Rather than specify the size of the red box, you would define a red layer and then set the left margin of the white layer equal to the amount of red to show.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="#55FF0000" />
        </shape>
    </item>
    <item android:left="100px">
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFFFF"/>
        </shape>
    </item>
</layer-list>

If you know the desired negative space, you could even swap the two and set the right margin of the red (now top) layer to the amount of white that should be visible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top