i have created animation using following code.
private animationset rootset = new animationset(true); private int xstart=258; private int ystart=146; for(; k<points.length; k++) { if(k==1) { x1 = headx(xstart); y1 = heady(ystart); _animtime = 10; } else { x1 = headx(points[k-1][0]); y1 = heady(points[k-1][1]); } translate = new translateanimation((float)x1, (float)x2, (float)y1, (float)y2); translate.setduration(_animtime); translate.setfillafter(true); translate.setinterpolator(new acceleratedecelerateinterpolator()); totalanimtime += _animtime; translate.setstartoffset(totalanimtime); rootset.addanimation(translate); rootset.setfillafter(true); } imv1.startanimation(rootset);
it working fine. have add pause , play feature animation. how can that?
since have extended more information regarding explicity wanted use animationset
, have found solution should work you.
sample code:
a class extends animationset
need in order cancel animationset
:
public class customanimationset extends animationset { private animationlistener mcustomanimationsetlistener; public customanimationset(boolean interpolator) { super(interpolator); } public customanimationset(context context, attributeset attrs) { super(context, attrs); } @override public void setanimationlistener(animationlistener listener) { super.setanimationlistener(listener); mcustomanimationsetlistener = listener; } /** * cancel method.... */ public void cancel() { // make sure you're cancelling ongoing animationset. if(hasstarted() && !hasended()) { if(mcustomanimationsetlistener != null) { mcustomanimationsetlistener.onanimationend(this); } } // reset animationset's start time. setstarttime(float.min_value); } }
in activity
class:
private customanimationset manimationset; // init stuff. @override public void onclick(view v) { switch(v.getid()) { case r.id.onplaybutton: // might wanna add animations before starting next time? manimationset.start(); case r.id.onpausebutton: manimationset.cancel(); manimationset.reset(); } }
this example. @ moment not have opportunity test myself, written example purpose.
Comments
Post a Comment