Android中的循环动画ScrollView在重复之间暂停
问题描述:
我在Android中实现了一台老虎机。卷轴是带有LinearLayouts作为子项的ScrollViews,以及在LinearLayout内部垂直定向的作为ImageViews的各个tile。我使用ObjectAnimator滚动到ScrollView的末尾,使用ValueAnimator.RESTART和ValueAnimator.INFINITE。卷轴的滚动很好而且很流畅,但是当它重复时,它会暂停一秒,这会破坏效果。以下是我正在使用的代码:Android中的循环动画ScrollView在重复之间暂停
public void spinReel(SlotReel reel) {
final int reelSize = this.context.getPixelsInDPs(64);
final SlotMachineView me = this;
final SlotReel myReel = reel;
ImageView[] tiles = reel.getTiles();
int delta = tiles.length - reel.currentTileNumber();
ObjectAnimator animator = ObjectAnimator.ofInt(reel, "scrollY", tiles.length * reelSize);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(delta * 75);
animator.setStartDelay(0);
animator.setRepeatMode(ValueAnimator.RESTART);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
myReel.scrollTo(0, reelSize * 3);
}
});
animator.start();
}
请注意,无论是否将scrollTo放入Repeat回调中,都会出现急动度。
实例视频here:
除了提供一个答案,请解释为什么你的答案将有助于OP的问题。 – buczek 2016-07-13 16:40:32