资源$ NotFoundException:资源不是Drawable

时间:2012-04-29 22:23:10

标签: android

我正在尝试动态设置一个LayerList drawable标签内的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);

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

好的,当你调用getDrawable时,它需要引用你的drawable文件夹中的一个drawable。我不确定my_item_id是什么,但如果它是一个可绘制的尝试

LayerDrawable ld = (LayerDrawable) r.getDrawable(R.drawable.my_item_id); 
相关问题