Setting android:animateLayoutChanges programmatically

deimos1988 picture deimos1988 · Jun 5, 2014 · Viewed 35.6k times · Source

I am creating linearLayouts programmatically and would like them to fade in and out when the visibility is set to visible/gone.

I can set

android:animateLayoutChanges="true" 

in the xml-file, but since I am creating the views programmatically, I need to set it programmatically. How can I do that?

Answer

user3709904 picture user3709904 · Jun 5, 2014

Use this code:

container.setLayoutTransition(new LayoutTransition());

or

LayoutTransition lt = new LayoutTransition();
lt.disableTransitionType(LayoutTransition.DISAPPEARING);
container.setLayoutTransition(lt);