我试图将动画添加到我调用此类时运行的xml文件中
public class anim extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.anim.anim);
ImageView img = (ImageView)findViewById(R.anim.anim);
img.setBackgroundResource(R.anim.anim);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();
}
}
这是xml文件
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/bee00" android:duration="50" />
<item android:drawable="@drawable/bee01" android:duration="50" />
<item android:drawable="@drawable/bee02" android:duration="50" />
<item android:drawable="@drawable/bee03" android:duration="50" />
<item android:drawable="@drawable/bee04" android:duration="50" />
<item android:drawable="@drawable/bee05" android:duration="50" />
<item android:drawable="@drawable/bee06" android:duration="50" />
<item android:drawable="@drawable/bee07" android:duration="50" />
<item android:drawable="@drawable/bee08" android:duration="50" />
<item android:drawable="@drawable/bee09" android:duration="50" />
<item android:drawable="@drawable/bee10" android:duration="50" />
</animation-list>
当我运行我的应用程序时
Binary XML file line #3: Error inflating class animation-list
在LogCat窗口上,任何人都知道吗?
最佳答案
这是因为当应改用menu.xml文件(如documentation中所述)时,会用Animation xml文件的内容为偏好屏幕充气。
另外,当您在布局中找到特定 View 时,也应使用保存在R.id
中的ID值
然后,如果要使用帧动画,则应创建xml文件并将其存储在res/drawable
文件夹中,然后在设置图像的背景资源时使用R.drawable.filename
在代码中引用它。也请参阅this文档。
关于android - 二进制XML文件第3行: Error inflating class animation-list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9016959/