Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create android drawable consisting of two colors side by side?

Uisng XML is it possible to create a drawable where half of it would be color1 and another half would be color2? When I set that drawable as a background of a view it should look like in the image below.

enter image description here

like image 673
Egis Avatar asked Jun 30 '16 14:06

Egis


1 Answers

Doing it by xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="100dp">
    <shape android:shape="rectangle">
        <size android:height="100dp" android:width="100dp"/>
        <solid android:color="@android:color/black"/>
    </shape>
</item>

<item android:left="100dp">
    <shape android:shape="rectangle">
        <size android:height="100dp" android:width="100dp"/>
        <solid android:color="@android:color/holo_green_light"/>
    </shape>
</item>
</layer-list>

Put it in res/drawable folder and assign as android:background to image

like image 170
R. Zagórski Avatar answered Sep 18 '22 21:09

R. Zagórski