首页 > 解决方案 > Android BottomSheet 展开到另一个视图的底部

问题描述

我正在尝试使此底部工作表仅扩展到另一个视图的底部,但无法弄清楚。我希望locations_list_sheet扩展至view1.

我试过设置偏移量,bottomSheet.setExpandedOffset(48)但没有运气。我也尝试在底部工作表布局的顶部设置边距,但这看起来也不正确。

<layout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@android:color/transparent" />

        <include
            android:id="@+id/map_content"
            layout="@layout/content_locations_stoneco" />

        <include
            android:id="@+id/locations_list_content"
            layout="@layout/bottom_sheet_locations" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

布局

标签: androidandroid-coordinatorlayoutandroid-bottomsheetdialog

解决方案


我不知道您将哪个特定布局用作底页我认为它必须在其中一个包含的布局中......

android:translationY="48dp"为底部工作表布局添加一个属性

    <LinearLayout
            android:layout_width="match_parent"
            android:id="@+id/botto_sheet"
            android:translationY="48dp"
            android:background="@color/colorPrimary"          
            app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
            android:layout_height="match_parent"/>

它所做的基本上是将视图向下推......就像边距一样,但有点不同。

注意:我不知道这是否是正确的方法,但它确实有效......总是欢迎提出建议

顺便说一句,您可以添加上边距也都可以


推荐阅读