我有一个以协调器布局为父级的 Activity ,该 Activity 由工具栏和 viewpager tablayout 组成。该 Activity 有一个具有相对布局父级的 fragment ,并且嵌套在该相对布局中的是 recyclerview 和 Bottom Sheet 。
现在的问题是 Bottom Sheet 不能很好地与相对布局一起使用,但工具栏在 recyclerview 滚动事件上滚动得很好。 但是,当我使用协调器布局作为 fragment 布局的父级时, Bottom Sheet 工作正常但选项卡无法滚动,因此 Bottom Sheet 未完全显示。
我的问题:如何在相对布局父级中使用 bootomsheet。或者我仍然可以在 fragment 中使用 Coordinator 布局并且父选项卡仍然可以很好地滚动吗?
这是以相对布局作为根布局的 fragment 的代码:
<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>
这是以协调器布局为根布局的 fragment 的代码
<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>
这是我的标签布局 Activity 代码
<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 项目时滚动出 View ,而在向上滚动 recyclerview 项目时滚动到 View 中。
最佳答案
可以查看the doc :
BottomSheetBehavior
is applied to a child ofCoordinatorLayout
to make that child a persistent bottom sheet.
BottomSheetBehavior
与 CoordinatorLayout
协同工作,让您在 Bottom Sheet 单上显示内容。
关于android - 在具有相对布局父级的 fragment 中使用持久性 Bottom Sheet ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57922834/