android - Stop an animation and start again -
i want stop objectanimation while it's running, when click on animated imageview. then, want play frameanimation on imageview. after that, first animation starts again.
here onclicklistener:
onclicklistener click = new onclicklistener() { @override public void onclick(view arg0) { try { animator.wait(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } setframeanimation(view); } }; view.setonclicklistener(click);
animator objectanimator animation.
view imageview
my setframeanimation-method:
animationdrawable frameanimation = (animationdrawable)view.background(); frameanimation.start();
this code doesn't work. illegalmonitorstateexception when call wait().
use int duration = 150; img = (imageview)findviewbyid(r.id.imageview1); bitmapdrawable frame1 = (bitmapdrawable)getresources().getdrawable(r.drawable.y1); bitmapdrawable frame2 = (bitmapdrawable)getresources().getdrawable(r.drawable.y2); bitmapdrawable frame3 = (bitmapdrawable)getresources().getdrawable(r.drawable.y3); bitmapdrawable frame4 = (bitmapdrawable)getresources().getdrawable(r.drawable.y4); bitmapdrawable frame5 = (bitmapdrawable)getresources().getdrawable(r.drawable.y5); animation = new animationdrawable(); animation.addframe(frame1, duration); animation.addframe(frame2, duration); animation.addframe(frame3, duration); animation.addframe(frame4, duration); animation.addframe(frame5, duration); // animation.addframe(frame6, duration); // animation.addframe(frame7, duration); // animation.addframe(frame8, duration); // animation.addframe(frame9, duration); // animation.addframe(frame10, duration); img.post(new runnable() { @override public void run() { // todo auto-generated method stub animation.setoneshot(false); img.setbackgrounddrawable(animation); animation.start(); } }); btnstart = (button)findviewbyid(r.id.btnstart); btnstop = (button)findviewbyid(r.id.btnstop); btnstart.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub animation.start(); } }); btnstop.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub animation.stop(); } });
Comments
Post a Comment