2015-08-15 55 views
0

我剛剛在我的activity.xml中添加了DrawerLayout。遇到間距問題......我需要抽屜佈局才能坐在主線性佈局上方。現在得到一個錯誤,說:「多根標籤」。線性佈局上方的DrawerLayout

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


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

    <LinearLayout 
     android:id="@+id/container_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/toolbar" /> 
    </LinearLayout> 

    <FrameLayout 
     android:id="@+id/container_body" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 
</LinearLayout> 


<fragment 
    android:id="@+id/fragment_navigation_drawer" 
    android:name="com.example.my.app.FragmentDrawer" 
    android:layout_width="@dimen/nav_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:layout="@layout/fragment_navigation_drawer" 
    tools:layout="@layout/fragment_navigation_drawer" /> 

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

獲得以下多個根標籤錯誤:

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



<ImageButton 
    android:id="@+id/btn_lst_car" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_margin="8dp" 
    android:background="@android:color/transparent" 
    android:contentDescription="@null" 
    android:src="@android:drawable/ic_menu_add" /> 

<TextView 
    android:id="@+id/txt_empty_list_cars" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_margin="4dp" 
    android:gravity="center" 
    android:text="@string/view1" 
    android:textAppearance="?android:attr/textAppearance" 
    android:textColor="@android:color/darker_gray" 
    android:visibility="gone" /> 

<ListView 
    android:id="@+id/list_cars" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/txt_header" 
    android:layout_margin="4dp" 
    android:divider="@android:drawable/divider_horizontal_bright" 
    android:dividerHeight="0.5dp" 
    android:listSelector="@android:drawable/list_selector_background" /> 

<Button 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Logout" 
    android:id="@+id/btnLogout" 
    android:layout_alignBottom="@+id/txt_header" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

+0

發佈logcat的錯誤 –

+0

一次性發布整個layout.xml,不要分割它。 –

+0

我發佈的是整個layout.xml – neo

回答

0

只要刪除第二的LinearLayout ..那是你的問題。我希望聆聽可以幫助你:)

<!-- First Child represents the Activity layout --> 
<LinearLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    > 
    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar" 
     /> 
    <FrameLayout 
     android:id="@+id/frame_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:onClick="onButtonClickMain"/> 

    </FrameLayout> 
0

一個XML文檔只能有根元素,在第二個XML文件中你忘記關閉主標籤,所以這就是爲什麼你有Multiple root tags錯誤。

只需在文件末尾添加</LinearLayout>即可關閉主文件夾LinearLayout

0

我通過將整個事物包裝在RelativeLayout中解決了這個問題。