Setting android:animateLayoutChanges programmatically

Use this code:

container.setLayoutTransition(new LayoutTransition());

or

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

To disable the fade-out effect try this:

LinearLayout layout = (LinearLayout) findViewById(R.id.test_layout);
layout.setLayoutTransition(null);