我有这个图层列表:
<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>
我想以编程方式更改outer_satop_btn的填充底部,但我没有找到任何内容:
LayerDrawable bgDrawable = (LayerDrawable)v.getBackground();
final GradientDrawable shape1 = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.outer_satop_btn);
Rect padding = new Rect();
shape1.getPadding(padding);
我该怎么办? 感谢
答案 0 :(得分:1)
作为drawable,它必须放在ImageView上。例如。
您必须将填充放在绘制它的视图上。
使用LinearLayout作为imageViews parent的代码示例:
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);
希望这有帮助。
答案 1 :(得分:1)
您可以将其打包在InsetDrawable:InsetDrawable(shape1, 0, 5, 0, 5)