繁体   English   中英

如何在Android DrawerLayout中使用两个片段

[英]How use two fragment in Android DrawerLayout

我尝试使用Android NavigationDrawe - http://developer.android.com/training/implementing-navigation/nav-drawer.html我有一个活动和两个片段。 我的主要问题是android.support.v4.widget.DrawerLayout中的布局。 一个片段使用-content_frame和其他 - content_footer。 此元素将位于底部(height - wrap_content)。 我尝试了不同的变化,但没有奏效。 所有例子都有一个片段。 我做错了什么? 谢谢
我的主要布局文件。 用这个节目一个片段。

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

 <FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    >    
 </FrameLayout>

 <FrameLayout
    android:id="@+id/content_footer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    >    
 </FrameLayout>

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/abs__bright_foreground_disabled_holo_light"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" /> 
 </android.support.v4.widget.DrawerLayout>  

当改为:

     <RelativeLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         android:layout_gravity="start"
        >    
     </RelativeLayout>

     <RelativeLayout
        android:id="@+id/content_footer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        >    
     </RelativeLayout>
 </FrameLayout> 

显示两个片段,但彼此显示。 截图

如果我正确理解您的问题,您希望在顶部有一个片段,并且您希望第二个片段作为屏幕上的页脚。 目前还不清楚你是否想要滚动,所以我不会假设。 DrawerLayout实际上在根据我的知识布置元素方面做的并不多,所以我建议在DrawerLayout中放置一个布局来根据需要定位片段。 做一些类似于我将在下面提到的未经测试的代码:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
    android:weightSum="100">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="0dp"
            android:layout_weight="80" >
    </FrameLayout>

    <FrameLayout
        android:id="@+id/content_footer"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="20" >
    </FrameLayout>

</LinearLayout>

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/abs__bright_foreground_disabled_holo_light"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" />

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

祝你好运! 希望有所帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM