Android property animation: how to increase view height?

后端 未结 7 2188
不知归路
不知归路 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:30

    This is not a direct answer to this question. However, it may help someone.

    Sometimes, we want to increase/decrease view's height because some of its child is is being added/removed (or just becoming visible/gone).

    On those cases, you really can use Android default animation. As mentioned in other answers, you can set via:

    
    

    Or in Java:

    linearLayout.setLayoutTransition(new LayoutTransition());
    

    If you created a custom view:

    public StickerPickerView(final Context context, final AttributeSet attrs,
            final int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setLayoutTransition(new LayoutTransition());
    }
    

    For me, it was pretty satisfactory but I just tested on latest APIs. That will automatically add a fade in/out when your view becomes visible. It will also animate the height/width of your view when same changes (like when you change the visibility of one of the child views etc).

    So, I recommend to at least give a try.

提交回复
热议问题