問題:
Here's my layout code; 這是個人佈局代碼; android
<?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>
What this looks like is on the left and what I want it to look like is on the right. 這看起來像在左邊,我但願它看起來像在右邊。 佈局
The obvious answer is to set the TextView to fill_parent on height but this causes no room to be left for the button or entry field. 顯而易見的答案是在高度上將TextView設置爲fill_parent,但這不會爲按鈕或輸入字段留下任何餘地。 Essentially the issue is that I want the submit button and the text entry to be a fixed height at the bottom and the text view to fill the rest of the space, similarly in the horizontal Linear layout I want the submit button to wrap its content and for the text entry to fill the rest of the space. 本質上問題是我但願提交按鈕和文本條目在底部是固定高度,文本視圖填充剩餘的空間,相似於水平線性佈局我但願提交按鈕包裝其內容和用於填充剩餘空間的文本條目。 ui
If the first item in a Linear Layout is told to fill_parent it does exactly that, leaving no room for other items, how do I get an item which is first in a linear layout to fill all space apart from the minimum required by the rest of the items in the layout? 若是線性佈局中的第一個項目被告知fill_parent它就是這樣作的,沒有其餘項目的空間,我如何得到一個線性佈局中的第一個項目來填充除了其他項目所需的最小空間以外的全部空間佈局中的項目? this
EDIT: 編輯: spa
Relative Layouts were indeed the answer - Thank you! 相對佈局確實是答案 - 謝謝! .net
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 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" android:layout_alignParentTop="true"> </TextView> <RelativeLayout android:id="@+id/InnerRelativeLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" > <Button android:text="@string/label_submit_button" android:id="@+id/Button" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <EditText android:id="@+id/EditText" android:layout_width="fill_parent" android:layout_toLeftOf="@id/Button" android:layout_height="wrap_content"> </EditText> </RelativeLayout> </RelativeLayout>
解決方案:
參考一: https://stackoom.com/question/A0vq/如何在屏幕底部對齊視圖參考二: https://oldbug.net/q/A0vq/How-to-align-views-at-the-bottom-of-the-screen