Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android animateLayoutChanges and anchored fab flicker

I have a FrameLayout which I replace on activity create with fragment where I show and hide some of the views with layout animation change, this works well, but I have a FloatingActionButton anchored to the frame layout and when the layout animates on hiding or showing view the fab flickers, as if there was no animation and those views dissapeared immediately, then goes back and animates with the view.

This really breaks the smoothnes of the whole transition so my question is did anyone else experience this? And is there a fix or workaround for this bug?

like image 658
TheDivider Avatar asked Aug 31 '15 07:08

TheDivider


1 Answers

This issue still seems to exist in SDK 29 with certain elements, such as those with innate transitions. The way I've fixed it is by applying the below flags to the CoordinatorLayout ViewGroup after setting the attribute android:animateLayoutChanges="true".

  cLayout.getLayoutTransition().disableTransitionType(LayoutTransition.APPEARING);
  cLayout.getLayoutTransition().disableTransitionType(LayoutTransition.DISAPPEARING);

This way, the transitions are not duplicated for the views that already include them.

Depending on your situation, you may consider disabling the other transition types instead: LayoutTransition.CHANGE_APPEARING

LayoutTransition.CHANGE_DISAPPEARING

like image 101
Bryan W Avatar answered Sep 23 '22 23:09

Bryan W