Setting android:animateLayoutChanges programmatically

AndroidAnimationDynamic

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

Use this code:

container.setLayoutTransition(new LayoutTransition());

or

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

Solution 2 - Android

To disable the fade-out effect try this:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondeimos1988View Question on Stackoverflow
Solution 1 - Androiduser3709904View Answer on Stackoverflow
Solution 2 - AndroidBobView Answer on Stackoverflow