问题:
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