如何将相对布局放置在屏幕底部(或线性布局)。

问题描述:

我在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

你想在底部的布局应该有:
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

我也在寻找这一点。我刚刚找到的解决方案是使用属性:

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

<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,它将把它底部。就像这样:

<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

尝试使用:

<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