Android 可以在导航抽屉中加载布局吗?

Android 可以在导航抽屉中加载布局吗?,android,Android,请告诉我如何在导航抽屉中加载另一个布局文件。 我在MainActivity.java中实现了导航视图,并创建了一个名为my_draw_layout.XML的XML文件。我需要在导航抽屉中加载我的_draw_layout.xml,还需要在主文件中加载事件。可能吗 MainActivity.java public class MainActivity extends AppCompatActivity { ImageView nav_click; NavigationView navigation

请告诉我如何在导航抽屉中加载另一个布局文件。 我在MainActivity.java中实现了导航视图,并创建了一个名为my_draw_layout.XML的XML文件。我需要在导航抽屉中加载我的_draw_layout.xml,还需要在主文件中加载事件。可能吗

MainActivity.java

public class MainActivity extends AppCompatActivity {

ImageView nav_click;
NavigationView navigationView;
private DrawerLayout drawerLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    drawerLayout = findViewById(R.id.drawerLayout);
    nav_click = findViewById(R.id.nav_click);
    navigationView =findViewById(R.id.nav_d);

    }
}
要加载到导航抽屉中的自定义XML文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:background="@color/colorPrimary">

    <TextView
        android:textColor="#ffff"
        android:textSize="40dp"
        android:text="FFFFF"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

<TextView
    android:id="@+id/t1"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:gravity="center"
    android:text="Text"
    android:textSize="30dp" />

<TextView
    android:id="@+id/t2"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:gravity="center"
    android:text="Text"
    android:textSize="30dp" />

<TextView
    android:id="@+id/t3"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:gravity="center"
    android:text="Text"
    android:textSize="30dp" />

<TextView
    android:id="@+id/t4"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:gravity="center"
    android:text="Text"
    android:textSize="30dp" />

<TextView
    android:id="@+id/t5"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:gravity="center"
    android:text="Text"
    android:textSize="30dp" />


是,您可以在导航抽屉中加载自定义视图 见以下代码:

<layout 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.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    tools:openDrawer="start">

    <include
        android:id="@+id/ll_Home"
        layout="@layout/layout_home" />

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="@dimen/_200sdp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@drawable/drawer_background"
        android:scrollbars="vertical"
        app:itemIconTint="@android:color/white"
        app:itemTextColor="@android:color/white"
        app:theme="@style/AppTheme">

        <include
            android:id="@+id/llDrawer"
            layout="@layout/nav_header" />

    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

nav_header.xml

<layout 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">
           <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/_10sdp"
            android:layout_toRightOf="@+id/profile_image"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tvusername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="@color/black"
                android:textSize="@dimen/_15sdp" />

                <TextView
                android:id="@+id/tvusername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="@color/black"
                android:textSize="@dimen/_15sdp" />

                <TextView
                android:id="@+id/tvusername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="@color/black"
                android:textSize="@dimen/_15sdp" />

               <TextView
                android:id="@+id/tvusername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="@color/black"
                android:textSize="@dimen/_15sdp" />

                <TextView
                android:id="@+id/tvusername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="@color/black"
                android:textSize="@dimen/_15sdp" />

                <TextView
                android:id="@+id/tvusername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="@color/black"
                android:textSize="@dimen/_15sdp" />

                <TextView
                android:id="@+id/tvusername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="@color/black"
                android:textSize="@dimen/_15sdp" />

                <TextView
                android:id="@+id/tvusername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="@color/black"
                android:textSize="@dimen/_15sdp" />


        </LinearLayout>
  </layout>