2015-12-07 40 views
0

嗨,我知道這個問題太愚蠢了,但這對於應用程序來說真的很重要。使用xml是很重要的。我面臨很多問題。如何在xml中使用DrawerLayout Android studio

它不允許我只是拖放東西,當我這樣做時,將它放置在其他位置。

我可以在裏面管理相對佈局,但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。任何幫助歡迎。謝謝閱讀。

回答

1

用於您的工具欄和片段。

組線性佈局爲垂直的方向,如下

<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> 
相關問題