I have a scrollable view with a constant bottom sheet in the coordinator layout.
Is it possible to automatically adjust the bottom margin to scrollable view when the bottom sheet is displayed? Otherwise, the bottom sheet overlaps some elements in a scrollable form.
The scroll_marginBottom attribute in a scrollable view is not always applicable, since the bottom sheet may be in a hidden state.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="Item 1"
android:gravity="center"
android:textColor="@android:color/black"
android:background="#ffbb3d"/>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="Item 2"
android:gravity="center"
android:textColor="@android:color/black"
android:background="#a4ff3d"/>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="Item 3"
android:gravity="center"
android:textColor="@android:color/black"
android:background="#3d77ff"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<FrameLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="100dp"
android:clipToPadding="true"
android:background="#e6e6e6"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Bottom sheet title"
android:padding="16dp"
android:textSize="16sp"/>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
In this example, the layout for βItem 3β is always below the bottom sheet.
Update
I found a solution using custom layout behavior in NestedScrollView.
The layout of the bottom sheet should be expanded from some "marker class", for example
public class BottomSheetFrameLayout extends FrameLayout {
}
Otherwise, you can define the bottom sheet by id, for example.
, instanceof BottomSheetFrameLayout :
public class BottomSheetScrollingViewBehavior extends AppBarLayout.ScrollingViewBehavior {
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
return dependency instanceof BottomSheetFrameLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
}
}