0

我有猫动画跳跃,它有 5 个可绘制对象,我想触摸猫并让它跳跃。

如果 android oneshot="false",则在触摸猫后它会一直跳下去。

<?xml version="1.0" encoding="utf-8"?>

<item android:drawable="@drawable/cat1" android:duration="250"></item>
<item android:drawable="@drawable/cat2" android:duration="250"></item>
<item android:drawable="@drawable/cat3" android:duration="250"></item>
<item android:drawable="@drawable/cat4" android:duration="250"></item>
<item android:drawable="@drawable/cat5" android:duration="250"></item>
<item android:drawable="@drawable/cat1" android:duration="250"></item>

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.page5);
    cat_jump = (ImageView)findViewById(R.id.cat_jump);
    cat_jump.setBackgroundResource(R.drawable.cat_jumping_animation);

    final AnimationDrawable frameAnimation = (AnimationDrawable) cat_jump.getBackground();

    cat_jump.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            frameAnimation.start();
        }
    });
4

1 回答 1

1

创建这个 oncreate

    ImageView iv = (ImageView)findViewById(R.id.cat_jump);
    AnimationDrawable aw = (AnimationDrawable) iv.getBackground();

    aw.stop();
    aw.start();

然后,

public void Start() {
    aw.stop();
    aw.start();
}

public void Stop() {
    aw.stop();

}
于 2015-06-09T07:19:43.267 回答