簡體   English   中英

片段上方的Android RelativeLayout

[英]Android RelativeLayout above Fragment

我正在嘗試在片段上方顯示RelativeLayout,但沒有成功。

這是我的xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#5C5A59"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:padding="5dp" >

    </RelativeLayout>

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

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center|bottom"
        android:background="#5C5A59"
        android:orientation="horizontal"
        android:paddingLeft="10dp"
        android:paddingRight="10dp" >

        <TextView
            android:id="@+id/lbl_altitude"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="@string/lbl_altitude"
            android:textColor="#00FFFF"
            android:layout_alignParentBottom="true" />

    </RelativeLayout>

</LinearLayout>

使用此代碼,Fragment總是占據整個屏幕的尺寸,而我的RelativeLayout不在isnt顯示屏上。

先感謝您。

嘗試使用layout_weight屬性

您可以閱讀本指南: 線性布局

如果您使用的是線性布局,則必須設置權重,這將根據百分比設置屏幕,例如,如果將權重總和1賦予父級,然后首先將布局權重0.2賦予布局,而將fragage賦予0.8這意味着您的布局獲得了20%的屏幕,其他碎片獲得了80%

因此,我認為您想使用“相對”布局作為父級,並在父級頂部設置第一個子級,然后將下面的部分設置為相對布局。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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