Search code examples
androidandroid-layoutanimationlayouttransition

LayoutTransitions not working for visibility changes


I'm trying to use LayoutTransition animations but they aren't working.

I set

android:animateLayoutChanges="true

in the parent LinearLayout in my Activity's layout. I then do a setVisibility(View.VISIBLE) or setVisibility(View.GONE) on a child LinearLayout that contains some checkBoxes when another CheckBox is checked or unchecked. The visibility change is not animated. There is a ScrollView inside the parent LinearLayout.

I've also tried setting layout transitions through programmatically with

LayoutTransition layoutTransition = new LayoutTransition();
layout.setLayoutTransition(layoutTransition)

but that had no effect either.

Where am I going wrong? This should be simple.

This is on Android 6.0.1 and using AppCompatActivity from the v23.2.0 support library.

EDIT: I noticed that some layout changes are animated. For example, when I set a recyclerView's visibility between VISIBLE and GONE, that is nicely animated. However simple layouts holding 3 checkboxes don't animate when their visibility is set to VISIBLE/GONE.


Solution

  • It looks like all the layouts who's contents you want you want animated each have to have the flag set. I thought that the animateLayoutChanges flag would be passed on to its children layouts, so I only set it on the parent layout, but it looks like it isn't.