Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在使用BottomNavigationView时仅显示片段区域?_Android_Xml_Android Fragments - Fatal编程技术网

Android 如何在使用BottomNavigationView时仅显示片段区域?

Android 如何在使用BottomNavigationView时仅显示片段区域?,android,xml,android-fragments,Android,Xml,Android Fragments,我目前正在使用android studio和Kotlin开发一个应用程序 此应用程序有一个BottomNavigationView和4个片段 我的问题是如何使用BottomNavigationView仅显示片段区域 ex)当我使用两个线性布局划分碎片区域时,每个线性布局都有不同的高度,如下图所示: 我想把每条直线分成相同的高度 代码如下: fragment.xml <?xml version="1.0" encoding="utf-8"?>

我目前正在使用android studio和Kotlin开发一个应用程序

此应用程序有一个BottomNavigationView和4个片段

我的问题是如何使用BottomNavigationView仅显示片段区域

ex)当我使用两个线性布局划分碎片区域时,每个线性布局都有不同的高度,如下图所示: 我想把每条直线分成相同的高度


代码如下:

fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              tools:context=".fragments.HowToUseFragment" android:orientation="vertical">
    <LinearLayout
            android:id="@+id/viewBag"
            android:visibility="visible"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@android:color/holo_blue_bright">
    </LinearLayout>
    <LinearLayout
            android:id="@+id/viewReceipt"
            android:visibility="visible"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@android:color/holo_blue_dark">
    </LinearLayout>
</LinearLayout>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

    <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="?android:attr/windowBackground"
            app:menu="@menu/bottom_navigation_menu"/>
    <fragment
            android:id="@+id/nav_host_fragment"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:name="androidx.navigation.fragment.NavHostFragment"
            app:navGraph="@navigation/navigation_graph"/>
</FrameLayout>



Android Studio:3.3.2

尝试
LinearLayout
而不是
FrameLayout

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <fragment
        android:id="@+id/nav_host_fragment"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:name="androidx.navigation.fragment.NavHostFragment"
        app:navGraph="@navigation/navigation_graph"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/bottom_navigation_menu"/>
</LinearLayout>


或者将android:layout\u marginBottom=“56dp”添加到您的

谢谢您的支持,
线性布局
如我所愿!