0

I have an animation in imageview, I want to switch the second animation After the second animation running once, then return to the previous

I add a OnClickListener and tried setOneShot(true) and if (ad.isRunning() == false) but it only runnind oneshot and then stop running

This is my code

anim_doll = (ImageView) findViewById(R.id.anim_doll);
ad = (AnimationDrawable) anim_doll.getDrawable();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                ad.start();
            }
        }, 300);

anim_doll.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        anim_doll.setImageResource(R.drawable.doll_touch);
        // 核心实现代码
        ad = (AnimationDrawable) anim_doll.getDrawable();
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                ad.start();
                ad.setOneShot(true);

                if (ad.isRunning() == false) {
                    anim_doll.setImageResource(R.drawable.doll_normal);
                }
            }
        }, 300);
    }
});
Xiayan
  • 5
  • 3

0 Answers0