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
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);
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.
Removing the following line from my root layout solved this problem:
android:animateLayoutChanges="true"
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>
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);
}
}
});
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