Java 如何使我的片段适合我的工具栏和底部导航栏之间,并且仍然可以滚动?

Java 如何使我的片段适合我的工具栏和底部导航栏之间,并且仍然可以滚动?,java,android,android-fragments,Java,Android,Android Fragments,因此,我将在下面提供我的主要活动布局文件,以便您了解正在发生的事情 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.andro

因此,我将在下面提供我的主要活动布局文件,以便您了解正在发生的事情

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <include
        android:id="@+id/toolbar"
        layout="@menu/toolbar"/>

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_nav">
    </FrameLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/bottom_navigation"
        app:itemIconTint="@android:color/white"
        android:background="#39b54a"
        app:labelVisibilityMode="unlabeled">
    </com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>

这种布局的问题在于,顶部和底部导航栏上的工具栏覆盖了我的片段中的内容。另外,我的一个片段有一个包含许多项目的recyclerview,不知为什么我无法向下滚动?有没有一种方法可以使这些片段恰好适合工具栏和底部导航,比如调整自身大小以适合该区域而不剪切内容,并且仍然可以滚动?

这样做

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar_layout"/>  <!--include your layout file here -->

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_below="@id/toolbar"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_nav">
    </FrameLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/bottom_nav_menu"
        app:itemIconTint="@android:color/white"
        android:background="#39b54a"
        app:labelVisibilityMode="unlabeled">
    </com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>

顺便说一下,您应该在工具栏布局中设置一个布局资源文件,同时包括但传递菜单资源文件。也相应地改变那

像这样做

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar_layout"/>  <!--include your layout file here -->

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_below="@id/toolbar"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_nav">
    </FrameLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/bottom_nav_menu"
        app:itemIconTint="@android:color/white"
        android:background="#39b54a"
        app:labelVisibilityMode="unlabeled">
    </com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>


顺便说一下,您应该在工具栏布局中设置一个布局资源文件,同时包括但传递菜单资源文件。也相应地改变那

将该文件保存在“菜单”文件夹中有问题吗?@GoldNerd要保持干净,我建议您将所有布局文件仅保存在“布局”文件夹中。。。我不确定它是否抛出错误将该文件保存在“菜单”文件夹中是否有问题?@GoldNerd要保持干净,我建议您将所有布局文件仅保存在“布局”文件夹中。。。我不确定它是否抛出错误