Android: add view with expand animation (without blinking)

后端 未结 1 1342
甜味超标
甜味超标 2020-12-30 10:37

I want to add a view to a view group using an expanding animation, so the added view starts very small and takes more and more space until it reaches its full size (probably

1条回答
  •  攒了一身酷
    2020-12-30 11:26

    This might be a little simpler:

    public void expand(final View view) {
        view.getLayoutParams().height = 0;
    
        Animation a = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t)
            {
                view.getLayoutParams().height = (int)(mTargetHeight * interpolatedTime);
                view.requestLayout();
            }
    
            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };
    
        a.setDuration(1000);
        view.startAnimation(a);
    }
    

    0 讨论(0)
提交回复
热议问题