Android BottomSheet展开到另一个视图的底部
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>
答案
我相信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" />
另一答案
我不知道您要使用哪种特定布局作为底表,我认为它必须位于其中包含的布局中...
为底部工作表布局添加属性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"/>
它所做的基本上是将视图推低,就像边距一样,但是有点不同。
注意:我不知道这样做是否正确,但确实工作...总是欢迎提出建议
以上是关于Android BottomSheet展开到另一个视图的底部的主要内容,如果未能解决你的问题,请参考以下文章
Android BottomSheet 覆盖了锚定 ImageView 的一半
我们如何在 android 的 RecyclerView 片段中使用 bottomSheet?