在CoordinatorLayout中删除多余的顶部空间-Android [英] Removing the extra top space in CoordinatorLayout- Android
问题描述
我正在尝试使用BottomSheetBehavior
进行类似于Google地图提供的布局.我成功使用了BottomSheetBehavior
并创建了向上滑动的布局.我现在遇到的问题是,即使我的布局折叠起来,CordinatorLayout
也会占用额外的空间.
下面是我的布局的屏幕截图.
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.
- 主要活动布局中的白色背景
- 粉红色是我用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
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>
推荐答案
您必须在活动布局中使用CoordinatorLayout. 然后在您的底部工作表布局中插入以下行:
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"
这篇关于在CoordinatorLayout中删除多余的顶部空间-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!