Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the extra top space in CoordinatorLayout- Android

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.

enter image description here enter image description here

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>

like image 984
viper Avatar asked Aug 02 '19 11:08

viper


1 Answers

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"
like image 168
No Body Avatar answered Oct 26 '22 11:10

No Body