1
當我嘗試通過幀動畫圖像和ImageView
時,出現異常。下面是代碼:使用ImageView動畫圖像
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView rocketImage = (ImageView) findViewById(R.id.imageView1);
rocketImage.setBackgroundResource(R.drawable.animation_sample);
AnimationDrawable rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.run();
}
和我animation_sample.xml
<frames id="anim_sample" oneshot="false">
<frame drawable="@drawable/a1" duration="50" />
<frame drawable="@drawable/a2" duration="50" />
<frame drawable="@drawable/a3" duration="50" />
<frame drawable="@drawable/a4" duration="50" />
<frame drawable="@drawable/a5" duration="50" />
</frames>
和main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/imageView1" android:src="@drawable/icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
我缺少什麼(在manifest.xml文件或任何其他)?
什麼是不工作?你有任何錯誤?請更具體 – 2011-06-08 11:28:34