这是我的LayerList的简化版本.它在项目中有一个位图以防止缩放.我想以编程方式更改此位图的drawable.有没有办法做到这一点?
android:id="@+id/item"
android:left="165dp"
android:top="245dp" >
android:id="@+id/bitmap"
android:src="@drawable/tag_de_01"
android:gravity="top|left" />
我尝试了以下但没有成功:
Resources res = getResources();
LayerDrawable layerDrawable = (LayerDrawable) res.getDrawable(R.drawable.layer_list_drawable);
Drawable newDrawable = (Drawable)res.getDrawable(R.drawable.something);
// works, but scales the image because the drawable of the item is set instead the one of the bitmap
layerDrawable.setDrawableByLayerId(R.id.item, newDrawable);
// doesn't work at all
layerDrawable.setDrawableByLayerId(R.id.bitmap, newDrawable);