Removing the extra top space in CoordinatorLayout- Android

你说的曾经没有我的故事 提交于 2020-02-03 05:11:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!