我想使用一个自定义的drawable给我的按钮圆角。但是,我也希望矩形的底部1/4填充特定的颜色。这可能吗?我如何才能填补最差的季度?
是的,如果您使用“图层列表”并定义重叠的项目,则是可能的。这是一个例子
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="0dp" android:left="0dp" android:bottom="0dp" android:right="0dp">
<shape android:shape="rectangle">
<corner android:radius="5"/>
<solid android:color="#f000"/>
<size android:width="200dp"
android:height="30dp"/>
</shape>
</item>
<item android:top="0dp" android:left="0dp" android:bottom="0dp" android:right="0dp">
<shape android:shape="rectangle">
<corner android:radius="5"/>
<solid android:color="#0f0"/>
<size android:width="50dp"
android:height="30dp"/>
</shape>
</item>
</layer-list>
您可能需要尝试这些值,并根据需要进行调整
我认为您无法指定相对值(以百分比表示)。但是,如果这些值根据屏幕大小而有所不同,则可以(并且我建议)将该值移动到如下所示的尺寸资源文件中...
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="button_full_width">200dp</dimen>
<dimen name="button_quarter_width">50dp</dimen>
<dimen name="button_height">30dp</dimen>
</resources>
然后在可绘制对象中指定这些尺寸,如下所示...
...
<size android:width="@dimen/button_full_width"
android:height="@dimen/button_height"/>
...
现在,要为不同的屏幕尺寸指定不同的值,您需要通过添加不同的“值”资源文件夹并将尺寸文件置于其中以不同的值来指定针对不同尺寸的资源限定符。Android系统会在运行时根据设备屏幕尺寸获取并加载必要的尺寸...
res/
values/
dimens.xml
values-small/
dimens.xml
values-normal/
dimens.xml
values-large/
dimens.xml
values-xlarge/
dimens.xml
有关更多信息,请查阅文档
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句