我想创建一个具有两种纯色(水平方向)的矩形来实现这样的效果:
我听说过 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/