android - 具有两种纯色的矩形

标签 android android-xml shapes

我想创建一个具有两种纯色(水平方向)的矩形来实现这样的效果:

enter image description here

我听说过 layer-list,虽然我可以用它来包含两个不同颜色的矩形,但它似乎只能垂直放置形状。

有没有办法使用 lalyer-list 来实现这一点,还是我应该使用完全不同的东西?我想通过在运行时更改形状颜色的能力来保持简单。

谢谢。

最佳答案

这肯定会根据您的要求绘制形状:

调整 <item> 的大小如您所愿!

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

    <item
        android:left="50dip">
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle" >
            <solid android:color="#0000FF" />
        </shape>
    </item>
    <item android:right="50dip">
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle" >
            <solid android:color="#ff0000" />
        </shape>
    </item>

</layer-list>

关于android - 具有两种纯色的矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17630432/

相关文章:

android - 如何强制 eclipse 将 xml 布局和样式显示为文本?

c++ - OpenCV - 查找轮廓图像的高度和宽度

c# - 如何在 WPF C# 中更改 slider 上刻度的设计(刻度的厚度、刻度的形状等...)

Android形状按钮点击区域

android - 像android中的卡片一样布局

android - Android 中的错误 "Dataset and renderer should be not null and should have the same number of series"

android - overridePendingTransition:在 Activity 中从右到左滑动深度

android - setOnChronometerTickListener 的问题

android - 异构网格布局

android - 如何在android中的xml中创建一个二维数组?