DrawerLayout主界面被领航界面覆盖

DrawerLayout主界面被导航界面覆盖
本帖最后由 xiaoguohaha 于 2013-10-04 16:00:58 编辑

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

<include layout="@layout/main_layout"/>
<include layout="@layout/module_layout"/>
<include layout="@layout/user_layout"/>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>


include第一个是主界面的布局,后面两个include是左右两边导航的布局,但是打开运行的时候总是显示最后一个导航的布局,求解,statckflow貌似没有这方面的问题,而且英文水平有限,官方文档一知半解。
android layout DrawerLayout include

------解决方案--------------------
left drawer 需要定义属性 android:layout_gravity="start" 以及 android:layout_width < 320dp
同理 right drawer 需要 android:layout_gravity="end" 以及 android:layout_width < 320dp

没测试过include的情况, include 后面应该不允许直接跟这两个属性吧?

你可尝试在 user_layout 定义android:layout_gravity = "right" 以及指定一个小于320dp的宽度,
module_layout同样对待 ("start" 通 "left", "end" 通 "right")

为什么要include? 为了复用? 若为了复用, 可尝试

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v4.widget.DrawerLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/drawer_layout">
         
        <include layout="@layout/main_layout"/>
        <LinearLayout
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start">
            <include layout="@layout/module_layout"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/right_drawer"
            android:layout_width="300dp"
            android:layout_height="match_parent"
            android:layout_gravity="end" >
            <include layout="@layout/user_layout"/>
        </LinearLayout>
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>


另外: 没看出最外层 RelativeLayout 的必要性, 你可看看Lint建议