动画电车
if (tram != null && pagePosition == 0 ){
final Animation animation1=new TranslateAnimation(-100f, 80.0f, 0.0f, 0.0f);
animation1.setDuration(3000);
animation1.setRepeatCount(0);
tram.startAnimation(animation1);
animation1.setFillAfter(true);
animation1.setRepeatMode(0);
}
将幻灯片翻译到下一张幻灯片时,我想停止动画。 每当翻译幻灯片时它都会重复动画
答案 0 :(得分:0)
这可以帮到你:
public class CustomTranslateAnimation extends TranslateAnimation {
public CustomTranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta,
float toYDelta) {
super(fromXDelta, toXDelta, fromYDelta, toYDelta);
}
private long mElapsedAtPause = 0;
private boolean mPaused = false;
@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;
}
}