簡體   English   中英

如何在同一布局中垂直加載兩個片段?

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

我正在為我的大學的SafeWalk程序開發一個應用程序,並且正在嘗試進行一項活動,該活動將顯示一個地圖片段,其下方帶有一個帶有緊急呼叫按鈕的按鈕欄。 我遇到的問題是,當我加載以下布局文件時,僅顯示地圖片段,而不顯示底部的按鈕。

注意:我還在此布局中使用了導航抽屜,因此,在發生沖突的情況下,我將其包括在內。

我嘗試更改兩個父FrameLayouts的layout_width和layout_height值,但我只能獲得以下兩個結果之一:整頁的地圖或整頁的按鈕(拉伸到頂部)。 如果需要,我可以附加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" />

遵循以下Android-er-naut的建議,我得到了以下結果:(這是一種改進,但是按鈕需要更大一些並適合屏幕寬度。)

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

這個怎么樣 -

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM