【发布时间】:2019-03-19 23:54:58
【问题描述】:
是否可以使用ValueAnimator 到wrap_content 制作动画?这似乎只适用于常量值。
public static void valueAnimate(final View obj, int from, int to, Interpolator interpolator, long duration, long delay){
ValueAnimator anim = ValueAnimator.ofInt(from, to);
anim.setInterpolator(interpolator == null ? DEFAULT_INTERPOLATOR : interpolator);
anim.setDuration(duration);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Integer value = (Integer) animation.getAnimatedValue();
obj.getLayoutParams().height = value.intValue();
obj.requestLayout();
}
});
anim.setStartDelay(delay);
anim.start();
}
如何将to 参数作为wrap_content 传递?
Animator.valueAnimate(mapUtilsContainer, CURR_MAPUTILC_H, 800, OVERSHOOT, 300, 0);
【问题讨论】:
-
你尝试过 animateLayoutChanges 吗? proandroiddev.com/…
-
是的,不是我要找的。这是在使用布局参数和默认动画。我需要使用
ValuAnimation -
您是否要扩展原本隐藏的视图?
-
@noahutz 是的,
RelativeLayout将在 0 和 wrap_content 之间切换