首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何阻止fragment中的RecyclerView向下压下并隐藏BottomNavigationView?

如何阻止fragment中的RecyclerView向下压下并隐藏BottomNavigationView?
EN

Stack Overflow用户
提问于 2021-07-14 03:28:47
回答 1查看 23关注 0票数 0

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

BottomNavigationView的主要活动

代码语言:javascript
复制
<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的片段

代码语言:javascript
复制
<?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>

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

代码语言:javascript
复制
private fun setCurrentFragment(fragment: Fragment) {
        supportFragmentManager.beginTransaction().apply {
            replace(R.id.fragment_container, fragment)
            commit()
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2021-07-14 05:13:55

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

将片段中的layout_height = "match_parent“替换为layout_height = "wrap_content”(首先尝试循环视图,然后尝试约束布局,如果没有,请尝试同时更改循环视图和约束布局)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68368349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档