2015-08-15 23 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中解决了这个问题。