【问题标题】:How using DrawerLayout,NavigationView,CoordinatorLayout如何使用 DrawerLayout、NavigationView、CoordinatorLayout
【发布时间】:2020-05-17 21:34:04
【问题描述】:

我正在使用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】:

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

    【讨论】:

    • 之后,它在工具栏上显示了我的片段布局。
    • 你可以把toolbar和framelayout放到linearlayout中
    • 或将工具栏移出 CoordinatorLayout @S.M_Emamian
    猜你喜欢
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-13
    • 2015-09-24
    • 2015-08-23
    • 2015-08-25
    相关资源
    最近更新 更多