如何创建由两种颜色并排组成的android drawable?

Egi*_*gis 4 android drawable xml-drawable android-drawable

Uisng XML是否可以创建一个drawable,其中一半是color1而另一半是color2?当我将drawable设置为视图的背景时,它应该如下图所示.

在此输入图像描述

R. *_*ski 6

通过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>
Run Code Online (Sandbox Code Playgroud)

将它放在res/drawable文件夹中并指定为android:background图像