Andorid:如何将相对布局中的所有项目对齐到屏幕底部

时间:2017-09-10 03:20:56

标签: android android-layout android-linearlayout android-relativelayout

我在相对布局中放置了一个线性布局,我试图将父相对布局与屏幕底部对齐。

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom">
        <TextView
            android:id="@+id/fruits"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Fruits"
            android:layout_centerHorizontal="true"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16sp"
            android:layout_alignParentBottom="true"
            android:gravity="bottom">
            <TextView
                android:id="@+id/message"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="Message: " />
            <EditText
                android:id="@+id/message_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>
    </RelativeLayout>

我基本上试图将文本居中,并在其下面有一个文本和编辑文本,并将它们全部对齐到屏幕的底部

            Fruits
Message: ___________________________

5 个答案:

答案 0 :(得分:0)

改变这个:

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom">

到此:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom">

答案 1 :(得分:0)

使用android:layout_alignParentBottom="true"检查项目中运行以下解决方案。

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >
    <TextView
        android:id="@+id/fruits"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Fruits"
        android:layout_alignTop="@+id/linearLayout2"
        android:layout_centerHorizontal="true" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16sp"
        android:layout_alignParentBottom="true"
        android:gravity="bottom"
        android:id="@+id/linearLayout2">
        <TextView
            android:id="@+id/message"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="Message: " />
        <EditText
            android:id="@+id/message_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>
</RelativeLayout>

答案 2 :(得分:0)

你需要使用  的机器人:layout_alignParentBottom = “真”

#include <string.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <Misc.au3>
#include <AutoItConstants.au3>
#include <Date.au3>
#include <IE.au3>
#include <Inet.au3>

Local $oIE = _IECreate("www.google.com",1,1,1,1)
Sleep(2000)

_IELoadWait($oIE)
Sleep(2000)

$o_form = _IEFormGetObjByName($oIE, "f")
$element = _IEFormElementGetObjByName($o_form,"q")
_IEFormElementSetValue($element,"INDIA")
Sleep(2000)

;~ Send("{ENTER}")
;~ $btn = _IEFormElementGetObjByName($o_form,"gsr")
;~ _IEAction($element,"click")
_IEFormSubmit($o_form)
Sleep(2000)

 _IELinkClickByText($oIE, "India - Wikipedia")
 Sleep(3000)

;~  $Set = _IEFormGetObjByName($o_form,"search")
;~  _IEFormElementSetValue($Set,"MAHARASHTRA")
$OIE1 = _IEPropertyGet($oIE, 'locationurl')
_IELoadWait($OIE1)
Sleep(2000)

MsgBox($MB_SYSTEMMODAL,"","New Page",3)
;~ $form = _IEFormGetObjByName($OIE1,"searchform")
;~ $select = _IEFormElementGetObjByName($form,"searchInput")
;~ Sleep(2000)

;~ _IEFormElementSetValue($select,"MAHARASHTRA")
_IELinkClickByText($OIE1,"second-most populous")

答案 3 :(得分:0)

简单!您必须将父RelativeRayout的高度从wrap_content更改为match_parent 。因此它将占据整个布局的高度,它将附加到屏幕的底部。

答案 4 :(得分:0)

将layout_above属性设置为fruit TextView到底部LinearLayout 试试这个

<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
    android:id="@+id/fruits"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Fruits"
    android:layout_above="@+id/bottomLayout"
    android:layout_centerHorizontal="true"
    />
<LinearLayout
    android:id="@+id/bottomLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16sp"
    android:layout_alignParentBottom="true"
    android:gravity="bottom">
    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Message: " />
    <EditText
        android:id="@+id/message_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>
</RelativeLayout>