问题
I am trying to use BottomSheetBehavior
to make a layout similar to what google maps is providing. I am successful in using the BottomSheetBehavior
and create slide up layout. The problem I am having now is CordinatorLayout
takes extra space even when my layout is collapsed.
Below is a screenshot of my layout.
- White background in my main activity layout
- Pink is my collapsed layout with peekHeight
- And the grey background is the one which should be transparent but takes the extra space.
My main layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<include layout="@layout/sample_coordinator" />
</FrameLayout>
CordinatorLayout with BottomSheetBehavior
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/common_google_signin_btn_text_light_disabled">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="false"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<TextView
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@color/colorPrimary" />
</FrameLayout>
回答1:
You have to use CoordinatorLayout in your activity layout. Then in your bottom sheet layout insert these lines:
app:behavior_hideable="true"
app:behavior_peekHeight="Xdp"
来源:https://stackoverflow.com/questions/57325406/removing-the-extra-top-space-in-coordinatorlayout-android