2011-06-08 93 views
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文件或任何其他)?

+0

什么是不工作?你有任何错误?请更具体 – 2011-06-08 11:28:34

回答

1

尝试用这种animation_sample.xml

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/anim_sample" android:oneshot="false"> 
    <item android:drawable="@drawable/a1" android:duration="50" /> 
    <item android:drawable="@drawable/a2" android:duration="50" /> 
    <item android:drawable="@drawable/a3" android:duration="50" /> 
    <item android:drawable="@drawable/a4" android:duration="50" /> 
    <item android:drawable="@drawable/a5" android:duration="50" /> 
</animation-list> 

抱歉,如果有一些错误,但我没有在这里Eclipse和SDK

+0

幸运的是,只有ImageView的默认图像显示,但没有我提供的图像动画。 – 2011-06-08 12:25:05