gpt4 book ai didi

java - Android属性动画: how to increase view height?

转载 作者:IT老高 更新时间:2023-10-28 20:34:07 30 4
gpt4 key购买 nike

如何在 Android 中使用 Property Animations 增加 View 高度?

ObjectAnimator a = ObjectAnimator.ofFloat(viewToIncreaseHeight, "translationY", -100);
a.setInterpolator(new AccelerateDecelerateInterpolator());
a.setDuration(1000);
a.start();

translationY 实际上是移动 View 而不是增加高度。如何增加 View 的高度?

最佳答案

ValueAnimator anim = ValueAnimator.ofInt(viewToIncreaseHeight.getMeasuredHeight(), -100);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = viewToIncreaseHeight.getLayoutParams();
layoutParams.height = val;
viewToIncreaseHeight.setLayoutParams(layoutParams);
}
});
anim.setDuration(DURATION);
anim.start();

关于java - Android属性动画: how to increase view height?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32835397/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com