Android: animateLayoutChanges="true", what can I do if the fade-out effect is unwanted?

nomnom picture nomnom · Nov 13, 2013 · Viewed 29k times · Source

in my layout XML file:

<LinearLayout
   ...
   animateLayoutChanges="true"
   ... />

When I add and a View and to this layout and delete it, I can see both fade in and fade out effect. However, I need only the fade in effect. Could anyone tell me what I should do?

Answer

Infinite Recursion picture Infinite Recursion · Nov 19, 2013

You should remove animateLayoutChanges from layout XML file. Instead, create a LayoutTransition object at runtime and supply it to the layout with the setLayoutTransition() method.

private ViewGroup mContainerView;  

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_linear_layout);

    mContainerView = (ViewGroup) findViewById(R.id.container);
    LayoutTransition lt = new LayoutTransition();
    lt.disableTransitionType(LayoutTransition.DISAPPEARING);
    mContainerView.setLayoutTransition(lt);
}