2010-09-27 213 views
8

我在XML如何將相對佈局放置在屏幕底部(或線性佈局)。

有以下我想把第二線性佈局在屏幕的底部。 我該怎麼辦? 我有第二個相對佈局屬性設置爲底部,但底部處仍然沒有顯示..

**

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent">  
<RelativeLayout android:id="@+id/RelativeLayout01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
</RelativeLayout> 
<RelativeLayout android:id="@+id/RelativeLayout02" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
</RelativeLayout> 
<RelativeLayout android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_gravity="bottom"> 
</RelativeLayout> 
</LinearLayout> 

** Thanx提前

+0

我想把第二相對佈局在屏幕 – Sandy 2010-09-27 09:06:52

回答

11

你想在底部的佈局應該有:
android:gravity = "bottom"
及其母公司應該有:
android:layout_height="fill_parent"

+0

我設置了兩個以上物業的底部仍佈局是不是在底部的屏幕 – Sandy 2010-09-27 09:11:40

+0

@Sandy父級佈局是「根」佈局,即它完全填滿了屏幕?子佈局還應該有'android:layout_height =「wrap_content」'。發佈你的代碼將有助於:-) – fredley 2010-09-27 09:13:11

+0

Yaa父級佈局完全填充screen.Child有android:layout_height =「wrap_content」 – Sandy 2010-09-27 09:15:38

13

我也在尋找這一點。我剛剛找到的解決方案是使用屬性:

android:layout_alignParentBottom="true" 

,而不是現有的android:layout_gravity="bottom"

這不幸的是我的佈局具有附加RelativeLayout作爲根佈局時,其餘加入到它纔會起作用。也許情況並非總是如此,但擁有LinearLayout(即使在被告知使用fill_parent時),它只使用所有需要添加的元素的高度,並將其頁腳放置在底部。

我來到這個解決方案,尋找此相關的問題:How do I achieve the following result using RelativeLayout?

編輯在這裏,因爲在回答註釋格式迷路了: 你的意思是你不能重寫它或者它沒有工作?

我也有一個垂直的LinearLayout,我的新XML結構看起來(沒有佈局大小參數等)。像這樣:

<RelativeLayout> 
    <RelativeLayout 
     android:id="@+id/RelativeLayout01"> 
    </RelativeLayout> 
    <RelativeLayout 
     android:id="@+id/RelativeLayout02" 
     android:layout_below="@+id/RelativeLayout01"> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_below="@+id/RelativeLayout02" 
     android:layout_alignParentBottom="true"> 
    </RelativeLayout> 
</RelativeLayout> 
+0

Thanx回覆,但它不與我的佈局。 – Sandy 2010-10-22 06:53:43

+0

你有沒有試過用我的新例子重寫你的xml?如果它不工作,也許你可以給你想要的佈局更多的細節。 – sunadorer 2010-10-28 12:46:16

0
<Linearlayout android:layout_height="fill_parent" 
android:orinationtation="vertical" 
android:layout_width="fill_parent"> 

<RelativeLayout android:layout_height="0dp" 
android:layout_width="fill_parent" 
android:weight="1"> 
</RelativeLayout> 

<RelativeLayout 
android:layout_height="0dp" 
android:layout_width="fill_parent" 
android:weight="1" 
> 
</RelativeLayout> 



</Linearlayout > 
1

你應該把你的瀏覽最後佈局之前,權重爲1,它將把它底部。就像這樣:

<View android:id="@+id/emptySpace" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    /> 
+0

這應該是正確的答案! – 2016-03-10 13:12:21

1

嘗試使用:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffb3e5fc" 
    android:id="@+id/linearLayout1"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="bottom"> 
<Button 
    android:id="@+id/button1" 
    android:text="Left" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_toLeftOf="@+id/centerPoint" /> 
<TextView 
    android:id="@+id/centerPoint" 
    android:text="" 
    android:layout_width="1dip" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" /> 
<Button 
    android:id="@+id/button2" 
    android:text="Right" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_toRightOf="@+id/centerPoint" /> 
</RelativeLayout> 
</LinearLayout> 

It produces something that looks like this

相關問題