Android property animation: how to increase view height?

后端 未结 7 2207
不知归路
不知归路 2020-12-07 20:17

How to increase the view height using Property Animations in Android?

ObjectAnimator a = ObjectAnimator.ofFloat(viewToIncreaseHeight, \"translationY\", -100)         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 20:53

    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(); 
    

提交回复
热议问题