gpt4 book ai didi

android - 资源 $NotFoundException : Resource is not a Drawable

转载 作者:行者123 更新时间:2023-11-29 22:07:47 27 4
gpt4 key购买 nike

我正在尝试在 LayerList 可绘制对象的标记内动态设置 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);

任何帮助将不胜感激!

最佳答案

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

LayerDrawable ld = (LayerDrawable) r.getDrawable(R.drawable.my_item_id); 

关于android - 资源 $NotFoundException : Resource is not a Drawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10376537/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com