我正在尝试将动画添加到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窗口上任何人都知道??
答案 0 :(得分:0)
这是因为当你应该使用menu.xml文件时,你会使用动画xml文件的内容来夸大你的偏好屏幕,就像documentation中所描述的那样。
此外,当您在布局中找到特定视图时,您应该使用R.id
如果你想使用帧动画,你应该创建xml文件并将其存储在res/drawable
文件夹中,而不是在代码中引用它,当你为图像设置背景资源时使用R.drawable.filename
。请查看this文档。
答案 1 :(得分:0)
.xml
文件的开头必须为:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
//your items
</animation-list>
,并且必须位于res/drawable
目录中。
您的图像也必须位于res/drawable
目录中。 animation.start()
必须在onStart()
方法中调用
这是文档:
https://developer.android.com/guide/topics/graphics/drawable-animation
Pd:请确保不要使用太大的图像,我的设备内存不足。