如何在 xml Android 工作室中使用 DrawerLayout

How to work with DrawerLayout in xml Android studio

您好,我知道这个问题太愚蠢了,但这对应用程序来说确实很重要。使用 xml 是一件大事。我面临很多问题。

它不允许我拖放东西,当我这样做时,它会放置在其他位置。

我可以在相对布局中进行管理,但是 DrawerLayout 我不能做我想做的事。这是我的 XML

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"/>

        <!--  -->
        <fragment
            xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"

             android:id="@+id/fragment"
             android:name="corp.msf.com.facebookconnect.MainFragment"
            tools:layout="@layout/fragment_main"
           android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

我希望片段出现在上方和下方的工具栏中。但是片段占据了所有位置(在工具栏上重叠)。我如何指定以及如何轻松使用 xmls。欢迎任何帮助。谢谢阅读。

用于您的工具栏和片段。

如下设置线性布局的方向为垂直

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"/>

        <fragment
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
             android:id="@+id/fragment"
             android:name="corp.msf.com.facebookconnect.MainFragment"
            tools:layout="@layout/fragment_main"
           android:layout_width="match_parent"
            android:layout_height="match_parent" />

</LinearLayout>


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