0
我想暫停和恢復一個動畫設置(動畫設置中的所有動畫設置順序運行)。
我寫了這個代碼,但它不能正常工作(不來自同一個地方重新開始):暫停和恢復AnimatorSet Api <19
AnimatorSet animatorSet;
int startPosition = 0 ;
long playTime = 0;
public void playOrResume(Marker marker, List<LatLng> positions, final LatLngInterpolator latLngInterpolator) {
TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() {
@Override
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
return latLngInterpolator.interpolate(fraction, startValue, endValue);
}
};
animatorSet = new AnimatorSet();
Animator previous = null;
for (int i = startPosition ; startPosition < positions.size(); i++) {
LatLng finalPosition = positions.get(i);
Property<Marker, LatLng> property = Property.of(Marker.class, LatLng.class, "position");
ObjectAnimator animator = ObjectAnimator.ofObject(marker, property, typeEvaluator, finalPosition);
if (previous != null) {
animatorSet.play(animator).after(previous);
} else {
animator.setCurrentPlayTime(playTime);
animatorSet.play(animator);
}
previous = animator;
}
animatorSet.setDuration(300);
animatorSet.start();
}
public void pause() {
ArrayList<Animator> animators = animatorSet.getChildAnimations();
for(int i= 0 ; i < animators.size() ; i++) {
Animator animator = animators.get(i);
if (animator.isStarted()){
startPosition = i;
playTime = animator.getCurrentPlayTime();
animatorSet.cancel();
break;
}
}
}
@AHoneyBustard它不只是一個動畫師,這是一個AnimatorSet – ReZa
可以,但只能有一個持續的在這個動畫設定任何給定的時間動畫。你需要找到那個,並保存/恢復播放時間,所以簡歷是無縫的。 @Reza –
@AHoneyBustard @AHoneyBustard我加了吧,還是一樣的結果 – ReZa