Android BottomSheet展开到另一个视图的底部

问题描述 投票:0回答:2

我正在尝试使此底页仅扩展到另一视图的底部,但无法弄清楚。我想将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>

Layout

android android-coordinatorlayout android-bottomsheetdialog
2个回答
0
投票

我相信this library可以帮助您实现所需的目标!

站点示例:

<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="Main Content"
    android:textSize="16sp" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center|top"
    android:text="The Awesome Sliding Up Panel"
    android:textSize="16sp" />


0
投票

我不知道您要使用哪种特定布局作为底表,我认为它必须位于其中包含的布局中...

为底部工作表布局添加属性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"/>

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

注意:我不知道这样做是否正确,但确实工作...总是欢迎提出建议

© www.soinside.com 2019 - 2024. All rights reserved.