0

I have cat animation jumping, it has 5 drawables, i want to touch the cat and make it jump.

if android oneshot="false", after touching the cat it keeps jumping forever.

<?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();
        }
    });
ERJAN
  • 23,696
  • 23
  • 72
  • 146
  • Try View.OnTouchListener : http://developer.android.com/training/graphics/opengl/touch.html and ref : http://developer.android.com/reference/android/view/View.OnTouchListener.html. – Prashant Jun 09 '15 at 07:15

1 Answers1

1

create this oncreate

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

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

then,

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

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

}
AbuQauod
  • 919
  • 14
  • 30