我正在用Android实现一个老虎机。卷轴是ScrollViews,LinearLayouts作为子对象,单独的tiles作为ImageViews在LinearLayout中垂直定向。我使用ObjectAnimator滚动到ScrollView的末尾,使用ValueAnimator.RESTART和ValueAnimator.INFINITE。卷轴滚动很流畅,但当需要重复时,它会暂停一秒钟,这会破坏效果。下面是我使用的代码:
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放在重复回调中,都会发生突变。
视频here示例
发布于 2016-07-14 00:20:11
https://stackoverflow.com/questions/27258218
复制相似问题