Android动画中的Normal, reverse, alternate, alternate-reverse.<



animation-direction CSS属性设置动画是向前播放,向后播放,还是在向前和向后播放序列之间来回切换。是否有可能为Android动画编写代码,满足CSS Animation -direction中的normal, reverse, alternate, alternate-reverse值?

HTML5

/* Single animation */
animation-direction: normal;
animation-direction: reverse;
animation-direction: alternate;
animation-direction: alternate-reverse;
/* Multiple animations */
animation-direction: normal, reverse;
animation-direction: alternate, reverse, normal;

Android

switch (arg1) {
case "normal":
//Code here
break;
case "reverse":
//Code here
break;
case "alternate":
//Code here
break;
case "alternate-reverse":
//Code here
break;
}

第一个if语句用于将动画设置在向后位置。第二个if语句用于通过将第一个循环设置为正常而将第二个循环设置为反向来创建备用方向。

class ReverseInterpolator implements Interpolator {
private final TimeInterpolator delegate;
public ReverseInterpolator(TimeInterpolator delegate) {
this.delegate = delegate;
}
@Override
public float getInterpolation(float input) {
return delegate.getInterpolation(1 - input);
}
}
if (isReverseDirection) { // set animation reverse
ReverseInterpolator reverseInterpolator = new ReverseInterpolator(animator.getInterpolator());
CommonUtils.cast(animator, ValueAnimator.class, false).setInterpolator(reverseInterpolator);
}
if (isRepeatModeReverse && repeatCount != 0) { // create alternate direction
CommonUtils.cast(animator, ValueAnimator.class, false).setRepeatMode(ValueAnimator.REVERSE);
}

相关内容

  • 没有找到相关文章