【问题标题】:How to stop RecyclerView in fragment from pushing down and hiding the BottomNavigationView?如何阻止片段中的 RecyclerView 下推和隐藏 BottomNavigationView?
【发布时间】:2021-07-13 19:28:46
【问题描述】:

我的应用使用 BottomNavigationBar 在三个片段之间切换。其中一个片段在 ConstraintLayout 中包含一个 RecyclerView。 RecyclerView 将 BottomNavigationBar 向下推,使其不可见且无法使用。这是xml代码:

底部导航视图的主要活动

<LinearLayout
    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"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:layout_above="@id/bottom_navigation"
        android:id="@+id/fragment_container"
        />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        android:theme="@style/BottomNavigationTheme"
        app:labelVisibilityMode="unlabeled"
        app:menu="@menu/nav_menu"
        app:layout_scrollFlags="scroll|exitUntilCollapsed" />
</LinearLayout>

带有 RecyclerView 的片段

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layoutManager="LinearLayoutManager"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    </androidx.recyclerview.widget.RecyclerView>
</androidx.constraintlayout.widget.ConstraintLayout>

这就是我在片段容器中更改片段的方式

private fun setCurrentFragment(fragment: Fragment) {
        supportFragmentManager.beginTransaction().apply {
            replace(R.id.fragment_container, fragment)
            commit()
        }
    }

【问题讨论】:

    标签: android kotlin android-fragments android-recyclerview


    【解决方案1】:

    我是android新手,所以我的回答可能是错误的。

    将片段中的 layout_height = "match_parent" 替换为 recyclerview 到 layout_height = "wrap_content" (首先尝试使用 recyclerview,然后尝试使用 constraintlayout,如果不行,请尝试同时更改 recyclerview 和 constraintlayout)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多