Android: Expand/collapse animation

后端 未结 30 2673
说谎
说谎 2020-11-22 05:01

Let\'s say I have a vertical linearLayout with :

[v1]
[v2]

By default v1 has visibily = GONE. I would like to show v1 with an expand animat

30条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 05:25

    Use ValueAnimator:

    ValueAnimator expandAnimation = ValueAnimator.ofInt(mainView.getHeight(), 400);
    expandAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(final ValueAnimator animation) {
            int height = (Integer) animation.getAnimatedValue();
            RelativeLayout.LayoutParams lp = (LayoutParams) mainView.getLayoutParams();
            lp.height = height;
        }
    });
    
    
    expandAnimation.setDuration(500);
    expandAnimation.start();
    

提交回复
热议问题