如何创建由两种颜色并排组成的android drawable? [英] How to create android drawable consisting of two colors side by side?

查看:406
本文介绍了如何创建由两种颜色并排组成的android drawable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Uisng XML可以创建一个drawable,其中一半为color1,另一半为color2吗?当我将该可绘制对象设置为视图的背景时,其外观应如下图所示.

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.

推荐答案

通过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>

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

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

这篇关于如何创建由两种颜色并排组成的android drawable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆