如何使用DrawerLayout,NavigationView,CoordinatorLayout

时间:2020-05-17 21:34:04

标签: android drawerlayout navigationview

我正在使用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元素?

1 个答案:

答案 0 :(得分:0)

放在AHBottomNavigation的CoordinatorLayout布局顶部

   <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>