从动画列表中获取所有可绘制资源ID的方法是什么?

4
如果我有一个动画可绘制的xml文件(动画列表),我可以使用R.drawable.anim引用它,是否有一种方法可以将所有Drawable ID存储在数组中?
基本上我不想以某种方式加载xml文件并获取该动画中涉及的所有Drawable的列表。
这是我正在使用的动画xml。
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >

    <item
        android:drawable="@drawable/typer_step_1"
        android:duration="50"/>
    <item
        android:drawable="@drawable/typer_step_2"
        android:duration="50"/>
    <item
        android:drawable="@drawable/typer_step_3"
        android:duration="50"/>
    <item
        android:drawable="@drawable/typer_step_4"
        android:duration="50"/>

</animation-list>
1个回答

2

<string-array name="random_imgs">
    <item>@drawable/image1</item>
    <item>@drawable/image2</item>
    <item>@drawable/image3</item>
</string-array>

在您的活动中
   TypedArray imgs = getResources().obtainTypedArray(R.array.random_imgs);
   //get resourceid by index
   imgs.getResourceId(i, -1);
   // or set you ImageView's resource to the id
   mImgView1.setImageResource(imgs.getResourceId(i, -1));
   imgs.recycle();

1
但是这并不是从Animation-List xml文件中获取的...我想要从animationList中读取它。 - Snake

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接