This article mainly comes from: http://stackoverflow.com/questions/5828423/android-animation-pause-and-play-problem
Http://stackoverflow.com/questions/10006736/pause-and-resume-translate-animation
Android animation has been introduced in many articles.
Two instructions on Android Animation:
1. The animation we see is that the background resource of the control is floating, and the actual position of the control is not changed (you can verify it by adding a listener ).
2. The official website does not provide direct pause () and resume () excuses, but there are two existing excuses: setstarttime () and getstarttime (). Let's start from here.
The following describes a method:
Package COM. ideal. study; import android. view. animation. transformation; import android. view. animation. pause, resumepublic class translateanim extends {public translateanim (float fromxdelta, float toxdelta, float fromydelta, float toydelta) {super (fromxdelta, toxdelta, fromydelta, toydelta); // todo auto-generated constructor stub} private long melapsedatpause = 0; private Boolean mpaused = false; @ overridepublic Boolean gettransformation (long currenttime, transformation outtransformation) {If (mpaused & melapsedatpause = 0) {melapsedatpause = currenttime-getstarttime () ;}if (mpaused) setstarttime (currenttime-melapsedatpause); return. gettransformation (currenttime, outtransformation);} public void pause () {melapsedatpause = 0; mpaused = true;} public void resume () {mpaused = false ;}}
To call the pause () and resume () methods, you only need to create a new translateanim class.
The following is 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); return super.getTransformation(currentTime, outTransformation); } public void pause() { mElapsedAtPause=0; mPaused=true; } public void resume() { mPaused=false; }}