如何在屏幕底部對齊視圖?這是我的布局代碼;<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="@string/welcome"
android:id="@+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
<LinearLayout android:id="@+id/LinearLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom">
<EditText android:id="@+id/EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
<Button android:text="@string/label_submit_button"
android:id="@+id/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout></LinearLayout>這看起來像在左邊,我希望它看起來像在右邊。顯而易見的答案是在高度上將TextView設(shè)置為fill_parent,但這不會為按鈕或輸入字段留下任何余地。本質(zhì)上問題是我希望提交按鈕和文本條目在底部是固定高度,文本視圖填充剩余的空間,類似于水平線性布局我希望提交按鈕包裝其內(nèi)容和用于填充剩余空間的文本條目。如果線性布局中的第一個項(xiàng)目被告知fill_parent它就是這樣做的,沒有其他項(xiàng)目的空間,我如何獲得一個線性布局中的第一個項(xiàng)目來填充除了其余項(xiàng)目所需的最小空間之外的所有空間布局中的項(xiàng)目?
3 回答

蠱毒傳說
TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個贊
您可以通過在線性布局中嵌套相對布局來保持初始線性布局:
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:text="welcome" android:id="@+id/TextView" android:layout_width="fill_parent" android:layout_height="wrap_content"> </TextView> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:text="submit" android:id="@+id/Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true"> </Button> <EditText android:id="@+id/EditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toLeftOf="@id/Button" android:layout_alignParentBottom="true"> </EditText> </RelativeLayout></LinearLayout>
添加回答
舉報(bào)
0/150
提交
取消