BottomSheet fly away with visibility change

后端 未结 6 913
一个人的身影
一个人的身影 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条回答
  • 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);
    
    0 讨论(0)
  • 2020-12-28 18:15

    Change View.GONE to View.INVISIBLE. Since the View.GONE has no size, the bottom sheet can't compute the height of the child being updated.

    0 讨论(0)
  • 2020-12-28 18:17

    Removing the following line from my root layout solved this problem:

    android:animateLayoutChanges="true"
    
    0 讨论(0)
  • 2020-12-28 18:27

    Try to make the parent of bottomSheet an independent CoordinatorLayout without having any other child Views. For example:

    <RelativeLayout
        android:id="@+id/some_id"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <Some_View
        .../>
    
    
        <Some_Other_view>
            .
            .
            .</Some_Other_view>
    
        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
    
            <include
                android:id="@+id/included_layout"
                layout="@layout/bottom_sheet" />
        </androidx.coordinatorlayout.widget.CoordinatorLayout>
    </RelativeLayout>
    
    0 讨论(0)
  • 2020-12-28 18:27

    The BottomSheetBehavior has its own behavior by which you can get respective results. The following are the behavior of the bottomsheet.

    STATE_DRAGGING, STATE_SETTLING, STATE_EXPANDED, STATE_COLLAPSED, STATE_HIDDEN.

    Don't use visibility of any layouts.

    Use this behavior in your code like:

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int behaviorState = bottomSheetBehavior.getState();
            if (behaviorState == BottomSheetBehavior.STATE_EXPANDED) {
                bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            } else {
                bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            }
        }
    });
    
    0 讨论(0)
  • 2020-12-28 18:31

    May be this can help you! I can't comment so posting it as an answer

    Here

    for slide layout something same as bottom sheet but good

    0 讨论(0)
提交回复
热议问题