删除 CoordinatorLayout- Android 中多余的顶部 space
Removing the extra top space in CoordinatorLayout- Android
我正在尝试使用 BottomSheetBehavior
制作类似于 google 地图提供的布局。我成功地使用 BottomSheetBehavior
并创建了向上滑动布局。我现在遇到的问题是 CordinatorLayout
需要额外的 space 即使我的布局已折叠。
下面是我的布局截图。
- 我的主要 activity 布局为白色背景
- 粉红色是我用 peekHeight 折叠后的布局
- 而灰色背景本应是透明的,但多了space。
我的主要布局文件
<?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>
您必须在 activity 布局中使用 CoordinatorLayout。
然后在底部 sheet 布局中插入这些行:
app:behavior_hideable="true"
app:behavior_peekHeight="Xdp"
我正在尝试使用 BottomSheetBehavior
制作类似于 google 地图提供的布局。我成功地使用 BottomSheetBehavior
并创建了向上滑动布局。我现在遇到的问题是 CordinatorLayout
需要额外的 space 即使我的布局已折叠。
下面是我的布局截图。
- 我的主要 activity 布局为白色背景
- 粉红色是我用 peekHeight 折叠后的布局
- 而灰色背景本应是透明的,但多了space。
我的主要布局文件
<?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>
您必须在 activity 布局中使用 CoordinatorLayout。 然后在底部 sheet 布局中插入这些行:
app:behavior_hideable="true"
app:behavior_peekHeight="Xdp"