android-fragments - AndroidX Fragment recyclerview 出现在我的工具栏上,我需要 recyclerview 在工具栏下滚动
问题描述
我使用带有片段的主 Activity 创建了一个 AndroidX 应用程序。当我使用 recyclerview 转到我的片段时,recycler 视图出现在应用程序的工具栏上方。我需要的是recyclerview出现在工具栏下方......
这是带有工具栏的主视图
这是显示在该工具栏上的 recyclerview 片段:
activity_mail.xml 的代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<FrameLayout
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/bottom_nav_view"
app:layout_constraintEnd_toEndOf="@id/toolbar"
app:layout_constraintStart_toStartOf="@id/toolbar"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/toolbar"/>
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
app:itemBackground="@color/colorPrimaryDark"
app:itemTextColor="@drawable/nav_item_text"
app:itemIconTint="@drawable/nav_background"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fitsSystemWindows="true"
android:background="#002B49"
app:menu="@menu/drawer_view" />
</androidx.drawerlayout.widget.DrawerLayout>
编辑这是toolbar.xml的布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/products_toolbar"
android:layout_width="match_parent"
app:layout_scrollFlags="enterAlways"
android:background="@null"
android:layout_height="?attr/actionBarSize"
app:titleTextColor="@android:color/black"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/rsi_logo"
android:layout_alignParentStart="true"/>
<ImageButton
android:id="@+id/toolbar_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/menu"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_alignParentEnd="true"
android:contentDescription="@string/menubutton"/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
作为补充说明,这也发生在带有滚动视图的片段上。
解决方案
我试图复制您的问题(创建了一个 repo),但我没有找到您指定的问题。
屏幕截图:显示工具栏
所以我说问题很可能出在你的view.RecyclerFragment
代码上。似乎您将工具栏隐藏在您view.RecyclerFragment
的如果您也可以共享您的view.RecyclerFragment
代码会更好。