【问题标题】:Android BottomSheet expand to bottom of another viewAndroid BottomSheet 展开到另一个视图的底部
【发布时间】:2020-05-27 15:07:40
【问题描述】:

我正在尝试使此底部工作表仅扩展到另一个视图的底部,但无法弄清楚。我希望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>

【问题讨论】:

  • 一张你想要的图片会更好......找到快速解决方案
  • 尝试设置app:behavior_peekHeight="48dp" / 使用bottomSheetBehavior.setPeekHeight(48) 如此处所述-stackoverflow.com/a/35696248/6763544
  • @PraveenSP 添加了照片。我希望底部工作表扩展到布局顶部绿色条的底部。目前,它在绿色条的上方展开为全屏。

标签: android android-coordinatorlayout android-bottomsheetdialog


【解决方案1】:

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

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

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

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

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

【讨论】:

    【解决方案2】:

    我相信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" />
    

    【讨论】:

    • 首选尝试原生解决方案(没有外部库)。
    • 好的,它可能会帮助其他希望从底部扩展的人。我在我的一个旧项目中使用过它...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 2020-12-19
    • 1970-01-01
    相关资源
    最近更新 更多