我想用如下的导航抽屉为一个活动做一个布局:
Navigation drawer closed:
-------------------------
| |
| |
| |
| 1 |
| |
| |
| |
| |
| |
| |
| |
|-----------------------|
| 2 |
-------------------------
Navigation drawer open:
-------------------------
| | |
| | |
| 3 | |
| | 1 |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|-----------------------|
| 2 |
-------------------------第1节和第3节应该在同一个DrawerLayout中(在main_section中)。第2节和main_section应该在活动的同一层次上。
然而,DrawerLayout的文档指出,'DrawerLayout充当窗口内容的顶级容器,允许从窗口边缘提取交互式“抽屉”视图。因此,我想我计划用DrawerLayout实现什么是不可能的,因为我需要DrawerLayout作为父布局。
我应该怎么做才能实现上面的布局结构?
更新,也许我需要添加更多的需求细节。第2节不应受到导航抽屉状态的视觉或功能影响。因此,这意味着第2节不应该像第1节所做的那样,当抽屉打开时,触摸第2节不应该关闭抽屉。无论抽屉是否打开,第2节应始终主动响应用户交互。
发布于 2014-05-24 09:36:34
好的,我知道了。
下面是我的代码解决方案的片段:
fragment_navigation_drawer.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccc"
android:orientation="vertical"
tools:context=".NavigationDrawerFragment">
<!-- add the content of the Section 3 (the navigation drawer) here.
this entire xml file could be a listview
instead of a linear layout, btw. -->
</LinearLayout>fragment_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ccc"
tools:context=".MainActivity$PlaceholderFragment">
<!-- add the content of the Section 1 here. -->
</RelativeLayout>activity_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment android:id="@+id/navigation_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name=".NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
<!-- This button below itself is the Section 3. -->
<Button
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#F66"
android:onClick="test"/>
</LinearLayout>https://stackoverflow.com/questions/23797873
复制相似问题