android - 在具有相对布局父级的片段中使用持久底部表
问题描述
我有一个以协调器布局为父的活动,该活动由工具栏和 viewpager tablayout 组成。该活动有一个具有相对布局父级的片段,并且嵌套在这个相对布局中的是一个recyclerview和一个底部工作表。
现在的问题是底部工作表不适用于相对布局,但工具栏在 recyclerview 滚动事件上滚动良好。但是,当我使用协调器布局作为片段布局的父级时,底部工作表工作正常,但选项卡无法滚动,因此底部工作表未完全显示。
我的问题:如何在 relativelayout 父级中使用 bootomsheet。或者我仍然可以在片段中使用协调器布局并且父选项卡仍然可以很好地滚动?
以下是将相对布局作为根布局的片段的代码:
<RelativeLayout
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="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<include layout="@layout/report_question_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
这是以协调器布局作为根布局的片段的代码
<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="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<include layout="@layout/report_question_bottom_sheet"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
这是我的带有选项卡布局的活动的代码
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Bookmarks">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="fill"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我希望工具栏在向下滚动 recyclerview 项目时滚动出视图,并在向上滚动 recyclerview 项目时滚动到视图中。
解决方案
您可以查看文档:
BottomSheetBehavior
应用于一个子级CoordinatorLayout
以使该子级成为一个持久的底部工作表。
BottomSheetBehavior
协同工作CoordinatorLayout
,让您在底部工作表上显示内容。
推荐阅读
- firebase - 对于具有可变天数的事件,如何构建 Firestore 集合以查询每天的标签?
- node.js - 如何存储承诺的价值并在解决后使用它?
- javascript - Nodejs + Postgresql - 当重复或违反外键时,我如何处理插入多行查询
- laravel - 在特定时间后在 Laravel 中上传图像不会加载或显示在服务器上
- flutter-web - 共享偏好颤动网络问题
- javascript - 如何使用 Joi 为输入字段赋予 null 的初始值?
- android - android studio中的recyclerview项目事故(不良行为)
- ld - ld:禁止更改部分开始
- haskell - 我如何告诉阴谋集团在哪里可以找到亚历克斯和快乐,这样阴谋集团就不会试图建造它们?
- c# - 如何切片 ONNXRuntime 张量?