[英]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.