Android 更改GradientDrawable的填充

Android 更改GradientDrawable的填充,android,padding,android-drawable,Android,Padding,Android Drawable,我有这个图层列表: <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/outer_satop_btn"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rec

我有这个图层列表:

<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/outer_satop_btn">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle" >
            <corners android:radius="5dp" />
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>
    <item android:id="@+id/bottom_satop_btn">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle" >
            <corners android:radius="5dp" />
            <solid android:color="@color/satopButtonColor2" />
            <padding
                android:bottom="5dp" />
        </shape>
    </item>
    <item android:id="@+id/top_satop_btn">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle" >
            <solid android:color="@color/satopButtonColor" />
            <corners android:radius="5dp" />
        </shape>
    </item>
</layer-list>
我该怎么办?
谢谢

作为一个绘图工具,例如,它必须放在ImageView上

您必须在绘制它的视图上添加填充

使用LinearLayout作为imageViews父对象时的代码示例:

ImageView img = new ImageView(this);
img.setDrawable(shape1);
LinearLayout.LayoutParams prms = new LinearLayout.LayoutParams(WIDTH,HEIGHT);
prms.setPadding(LEFT,UP,RIGHT,BOTTOM);
linearLayout.addView(img,prms);
希望这有帮助。

您可以将其包装为:
可插入绘制(shape1,0,5,0,5)

ImageView img = new ImageView(this);
img.setDrawable(shape1);
LinearLayout.LayoutParams prms = new LinearLayout.LayoutParams(WIDTH,HEIGHT);
prms.setPadding(LEFT,UP,RIGHT,BOTTOM);
linearLayout.addView(img,prms);