我试图创建一个简单的Drawable,我想将它设置为视图的背景(使用 setBackgroundDrawable )。 我只想将可绘制对象的背景分成2个相等的矩形(50% - 50%),第一个填充黑色,第二个填充白色:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/back_color_1">
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:id="@+id/back_color_2">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
如何在drawable XML定义文件中指定每个形状的宽度为50%?类似于android:width="50%"。
(我正在使用Android 3.0,但我认为这是一个普遍的Android问题。)
P.S:您可以在CSS或XAML中完成此操作。