Java 如何在Android DroperLayout中使用两个片段

Java 如何在Android DroperLayout中使用两个片段,java,android,drawerlayout,Java,Android,Drawerlayout,我尝试使用安卓导航抽屉- 我有一个活动和两个片段。 我的主要问题是android.support.v4.widget.DrawerLayout中的布局。 一个片段使用-content\u frame,另一个片段使用-content\u footer。此元素将位于底部(高度-包裹内容)。我尝试过不同的变化,但没有成功。所有示例都包含一个片段。我做错了什么?谢谢你 我的主布局文件。这是一个片段 <android.support.v4.widget.DrawerLayout xmlns:andr

我尝试使用安卓导航抽屉- 我有一个活动和两个片段。 我的主要问题是android.support.v4.widget.DrawerLayout中的布局。 一个片段使用-content\u frame,另一个片段使用-content\u footer。此元素将位于底部(高度-包裹内容)。我尝试过不同的变化,但没有成功。所有示例都包含一个片段。我做错了什么?谢谢你
我的主布局文件。这是一个片段

<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>  

如果我正确理解您的问题,您希望在顶部有一个片段,并希望第二个片段作为屏幕上的页脚。不清楚你是否想要滚动,所以我假设你不想要。据我所知,抽屉布局实际上在布局元素方面做的不多,因此我建议在抽屉布局中放置一个布局,以根据需要定位片段。执行类似于我将在下面列出的未测试代码的操作:

<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>


祝你好运!希望有帮助

当我线性布局更改为:'android:layout\u width=“fill\u parent”'android:layout\u height=“fill\u parent”和@+id/content\u框架更改:android:layout\u height=“wrap\u content”android:layou weight=“1”工作并显示两个框架。工作但是请理解,为什么不与RelativeLayout合作。@egidijusb我刚刚做了一个编辑。现在它应该将20%的屏幕分配给页脚,将80%的屏幕分配给第一个片段。试试看。我的希望不是给你一个100%的工作示例,而是向你展示你可以在抽屉布局中使用布局,从而按照你的意愿定位事物。“如果你不知道如何使用RelativeLayout或LinearLayout,我也无能为力。”egidijusb刚刚看到了你的其他评论。它应该和一个相对的布局配合得很好。你一定是用错了。您必须将第一个片段设置为alignParentTop=“true”和alignParentLeft=“true”,并将其设置在页脚片段上方,并且必须将第二个片段设置为alignParentBottom=“true”和alignParentLeft=“true”。从这里开始,它应该只是简单的布局摆弄。工作吧。谢谢如果我要滚动内容框架,我必须在此位置滚动查看。是吗?@egidijusb是的,如果你想滚动顶部,请将内容框放在滚动布局中。
<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>