删除 CoordinatorLayout-Android 中多余的顶部空间

2024-06-21

我正在尝试使用BottomSheetBehavior制作类似于谷歌地图提供的布局。我成功地使用了BottomSheetBehavior并创建向上滑动布局。我现在遇到的问题是CordinatorLayout即使我的布局折叠,也会占用额外的空间。 下面是我的布局的屏幕截图。

  • 我的主要活动布局中的白色背景
  • 粉色是我用 peekHeight 折叠的布局
  • 灰色背景应该是透明的,但占用了额外的空间。

我的主布局文件

<?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 与 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>

您必须在活动布局中使用 CoordinatorLayout。 然后在底部工作表布局中插入这些行:

app:behavior_hideable="true"
app:behavior_peekHeight="Xdp"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

删除 CoordinatorLayout-Android 中多余的顶部空间 的相关文章

随机推荐