1

LayerList ドローアブルのタグ内で 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);

どんな助けでも大歓迎です!

4

1 に答える 1

2

getDrawable を呼び出すときは、ドローアブル フォルダー内のドローアブルの 1 つを参照する必要があります。my_item_id が何かはわかりませんが、drawable の場合は試してみてください

LayerDrawable ld = (LayerDrawable) r.getDrawable(R.drawable.my_item_id); 
于 2012-04-30T11:42:16.843 に答える