如何使用DrawerLayout,NavigationView,CoordinatorLayout?

问题描述 投票:0回答:1

我用的是 AHBottomNavigation 现在我有一个类,扩展了一个底部导航。AppCompatActivity.

现在我想在里面加载我的碎片,但我不知道xml元素的顺序。

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".activities.MainPage"
    android:fitsSystemWindows="true">



    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include layout="@layout/toolbar" />


        <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom" />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>




    <com.google.android.material.navigation.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end|right"
        android:background="#fff">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="#fff">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="#fff">
                <include layout="@layout/rightmenu" />

            </LinearLayout>

        </ScrollView>

    </com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>

我的布局: 我必须在哪里放一个 fragment 元素?

android drawerlayout navigationview
1个回答
0
投票

把CoordinatorLayout布局在AHBottomNavigation的顶部。

   <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Linearlayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
         >
        <include layout="@layout/toolbar" />

       //put here frame lyout to fragment added here
       //********************************************

                  <FrameLayout
                        android:id="@+id/frame_container"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                 app:layout_behavior="@string/appbar_scrolling_view_behavior" />
       //**************************************
       </Linearlayout>
        <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom" />


    </androidx.coordinatorlayout.widget.CoordinatorLayout>
© www.soinside.com 2019 - 2024. All rights reserved.