简体   繁体   English

如何在同一布局中垂直加载两个片段?

[英]How do I load two fragments vertically in the same layout?

I am making an app for my university's SafeWalk program and I am trying to make an activity that will display a map fragment with a button bar below it with emergency call buttons. 我正在为我的大学的SafeWalk程序开发一个应用程序,并且正在尝试进行一项活动,该活动将显示一个地图片段,其下方带有一个带有紧急呼叫按钮的按钮栏。 The problem I am running in to is that when I load the following layout file, only the map fragment is displayed, and not the buttons along the bottom. 我遇到的问题是,当我加载以下布局文件时,仅显示地图片段,而不显示底部的按钮。

Note: I am also using a navigation drawer in this layout so I have included that code in case it is conflicting. 注意:我还在此布局中使用了导航抽屉,因此,在发生冲突的情况下,我将其包括在内。

I have tried changing the layout_width and layout_height values of the two parent FrameLayouts and I only can obtain one of two results, a full page of map, or a full page of my buttons (stretched to the top). 我尝试更改两个父FrameLayouts的layout_width和layout_height值,但我只能获得以下两个结果之一:整页的地图或整页的按钮(拉伸到顶部)。 I can attach the layout for the CallButtonFragment if necessary, but it is a horizontal linear layout with the button bar style containing two buttons. 如果需要,我可以附加CallButtonFragment的布局,但这是一种水平线性布局,其按钮栏样式包含两个按钮。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:orientation="vertical" >

    <!-- The main content view -->

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/content_frame" >

        <fragment
            android:id="@+id/titles"
            android:name="edu.purdue.SafeWalk.CallButtonFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
</RelativeLayout>
<!-- The navigation drawer -->

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

Following the suggestion of Android-er-naut below, I have this result: (It is an improvement, but the buttons need to be a bit larger and fit the width of the screen.) 遵循以下Android-er-naut的建议,我得到了以下结果:(这是一种改进,但是按钮需要更大一些并适合屏幕宽度。)

使用下面的答案的建议,我明白了。

How about this - 这个怎么样 -

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<!-- The main content view -->

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

    <fragment
        android:id="@+id/titles"
        android:name="edu.purdue.SafeWalk.CallButtonFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

</LinearLayout>

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

相关问题 如何在同一活动的两个片段之间传递数据? - How Do I Pass Data Between Two Fragments On The Same Activity? 如何在Android Studio中的多个活动/片段中重用相同的xml背景布局? - How do I reuse the same xml background layout in multiple activities/fragments in Android Studio? 如何为具有相同内容的多个片段创建片段模板(具有变量和方法的类、布局)? - How do I create a fragment template(class with variables and methods, layout) for multiple fragments with the same content? 如何将更多同一类的片段添加到布局中? - How can I add more fragments of the same class to a Layout? 如何在布局中垂直居中两个TextView - How can I center two TextViews vertically within a Layout 我如何从适配器类的onClick方法中加载片段 - How do i load fragments out of onClick method in an adapter class 如何将片段加载到我的SlidingPaneLayout菜单中? - How do I load Fragments into my SlidingPaneLayout menu? 如何以编程方式向布局添加两个片段? - How to programmatically add two Fragments to a layout? 如何在一个活动中垂直显示两个片段(主片段和细节片段) - How to display two fragments vertically (master and detail) in one activity 如何在同一个 MainActivity 中交换片段? - How do I swap fragments, still within the same MainActivity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM