BottomSheet fly away with visibility change

后端 未结 6 942
一个人的身影
一个人的身影 2020-12-28 17:44

I have a bottom sheet with a NestedScrollView inside (see below). When I press on a FAB button, I want to make some parts in this NestedScrollView invisible. But when I chan

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 18:14

    I ran into this, took a while to figure out what was the cause.

    It's because you're using android:animateLayoutChanges, which surfaces a bug in either BottomSheetBehavior or CoordinatorLayout.

    Remove it and the BottomSheet will stop animating on its own when it shouldn't. Not a fix, but a workaround at least.

    --

    Update:

    Turns out that if you enable "animateLayoutChanges" programmatically by setting the LayoutTransition instance to use, you can set a flag on it that will prevent it from messing with views that are ancestors of the one you're using android:animateLayoutChanges on (aka: your BottomSheet container):

    LayoutTransition transition = new LayoutTransition();
    transition.setAnimateParentHierarchy(false);
    yourLinearLayoutThatNeedsLayoutAnimation.setLayoutTransition(transition);
    

提交回复
热议问题