Wednesday, 15 July 2015

android - How to pause animation for sometime? -



android - How to pause animation for sometime? -

can please tell me how apply pause animation in android.in next animation button moves bottom of screen center of screen.i have done far using below code.however want button wait time after has reached final position(at center of screen). next code.

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromxdelta="400%" android:toxdelta="-200%" android:repeatcount="infinite" android:duration="2000" android:fillafter="true" /> </set>

in java:

animation = animationutils.loadanimation(this, r.anim.alpha); a.reset(); image.clearanimation(); image.startanimation(a);

what need subclass animation type you'd utilize , add together methods pausing , resuming animation. here illustration alphaanimation:

public class pausablealphaanimation extends alphaanimation { private long melapsedatpause=0; private boolean mpaused=false; public pausablealphaanimation(float fromalpha, float toalpha) { super(fromalpha, toalpha); } @override public boolean gettransformation(long currenttime, transformation outtransformation) { if(mpaused && melapsedatpause==0) { melapsedatpause=currenttime-getstarttime(); } if(mpaused) setstarttime(currenttime-melapsedatpause); homecoming super.gettransformation(currenttime, outtransformation); } public void pause() { melapsedatpause=0; mpaused=true; } public void resume() { mpaused=false; } }

this maintain increasing starttime while animation paused, keeping finishing , keeping it's state when paused.

hope helps you.

android

No comments:

Post a Comment