且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何添加填充到梯度LT;形状>在Android的?

更新时间:2023-09-20 10:17:04

一个解决方案似乎是包装我的绘制与另一个绘制指定适当的填充。

One solution seems to be to "wrap" my drawable with another drawable that specifies the appropriate padding.

例如, list_divider.xml 是:

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

    <item
        android:left="6dp"
        android:right="6dp"
        android:drawable="@drawable/list_divider_inner" />

</layer-list>

然后 list_divider_inner.xml 将原来的绘制:

<?xml version="1.0" encoding="UTF-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

<gradient
    android:startColor="#ccd0d3"
    android:centerColor="#b6babd"
    android:endColor="#ccd0d3"
    android:height="1px"
    android:angle="0" />

</shape>

这将导致两个文件虽然规定一个简单的除法。我不知道是否有一种方法,只有一个文件,但做到这一点。

This results in two files to specify a simple divider though. I don't know if there's a way to do it with only one file though.