我有layer-list.xml
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
</item>
<item
android:id="+id/item_2"
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>
现在我想在运行时更改(top,right)
之类的项的某些属性。我可以通过
LayerDrawable layerDrawable = (LayerDrawable) v.getContext().getResources().getDrawable(R.drawable.layer_list);
GradientDrawable drawable2 = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.item_2);
drawable2.setColor(strokeColor[0]);
但我不知道如何更改top,right
。我该怎么改呢?
任何帮助或建议都将非常感激。
答案 0 :(得分:4)
尝试使用此方法: https://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html#setLayerInset(int,int,int,int,int)