我正在尝试逐帧动画,但它给了我一个关闭的力,我不确定它为什么给我一个关闭的力。在我看来一切都很好。
这是我的代码,希望有人可以提供帮助?提前致谢。
动画测试.java
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class AnimationTest extends Activity {
AnimationDrawable animation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AnimationDrawable animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.up), 500);
animation.addFrame(getResources().getDrawable(R.drawable.down), 500);
animation.setOneShot(false);
ImageView imageAnim = (ImageView) findViewById(R.id.imageView1);
imageAnim.setBackgroundDrawable(animation);
// start the animation!
animation.start();
}
}
activity_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/down"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>