我的列表视图项目有ExpandAnimation
:
public class ExpandAnimation extends Animation {
private AnimationCompletedCallback callback = null;
private View viewToAnimate = null;
private RelativeLayout.LayoutParams viewToAnimateLayoutParams = null;
private int marginStart = 0;
private int marginEnd = 0;
private boolean isVisibleAfter = false;
private boolean isEndedAlready = false;
public ExpandAnimation(AnimationCompletedCallback callback, View view, int duration) {
this.setDuration(duration);
this.callback = callback;
this.viewToAnimate = view;
this.viewToAnimateLayoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
this.isVisibleAfter = (view.getVisibility() == View.VISIBLE);
this.marginStart = this.viewToAnimateLayoutParams.bottomMargin;
this.marginEnd = (this.marginStart == 0 ? (0 - view.getHeight()) : 0);
view.setVisibility(View.VISIBLE);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation transformation) {
super.applyTransformation(interpolatedTime, transformation);
if (interpolatedTime < 1.0f) {
this.viewToAnimateLayoutParams.bottomMargin = this.marginStart + (int) ((this.marginEnd - this.marginStart) * interpolatedTime);
this.viewToAnimate.requestLayout();
} else if (!this.isEndedAlready) {
this.viewToAnimateLayoutParams.bottomMargin = this.marginEnd;
this.viewToAnimate.requestLayout();
if (this.isVisibleAfter) {
this.viewToAnimate.setVisibility(View.GONE);
}
this.isEndedAlready = true;
this.callback.onAnimationCompleted();
}
}
}
Thi Animation适用于Android 4.4+但是在Android 4.2上,例如动画就会被跳过。例如,当我将持续时间设置为500
时,我看不到500毫秒,而且当我打开它时视图立即崩溃。没有任何事情发生在500毫秒,而且视图立即扩大。这意味着0到500毫秒之间的所有步骤都没有显示。
为什么?
答案 0 :(得分:0)
奇怪。我正在使用var image = UIImage(named: "myimage.png");
我现在切换到RelativeLayout
并且动画现在可以正常工作。