【问题标题】:Removing the extra top space in CoordinatorLayout- Android移除 CoordinatorLayout- Android 中多余的顶部空间
【发布时间】:2019-08-02 11:16:02
【问题描述】:

我正在尝试使用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>

带有 BottomSheetBehavior 的 CordinatorLayout

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

【问题讨论】:

    标签: android android-layout material-design android-coordinatorlayout bottom-sheet


    【解决方案1】:

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

    app:behavior_hideable="true"
    app:behavior_peekHeight="Xdp"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-23
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-22
      相关资源
      最近更新 更多