我正在尝试在 LayerList drawable 的标签内动态设置 a 的 android:src。
为此,我需要访问该标签,但它不断失败:
android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=3 r=0x7f090142}
这是 LayerList 可绘制部分:
<item android:id="@+id/my_item_id"
android:left="35dip"
android:right="0dip"
android:top="0dip"
android:bottom="50dip">
<bitmap android:id="@+id/my_bitmap_id" android:gravity="left"/>
</item>
这是代码:
Resources r = view.getResources();
Drawable drawable = r.getDrawable(myDrawableId);
// it abends on this next line
LayerDrawable ld = (LayerDrawable) r.getDrawable(R.id.my_item_id);
// this is where I want to set the id of the drawable to use in the bitmap
ld.setDrawableByLayerId(myDrawableId, drawable);
任何帮助将不胜感激!