To layout an EditText and Button side-by-side like so:
Use the following:
LinearLayout
orientation:horizontal
EditText
layout_width="0dp"
layout_weight="1"
Button
layout_width="wrap_content"
With this the button has enough width to display its contents and then ensure that the edit box fills the rest of the width of the parent.
See here for more details.
Use the following:
LinearLayout
orientation:horizontal
EditText
layout_width="0dp"
layout_weight="1"
Button
layout_width="wrap_content"
With this the button has enough width to display its contents and then ensure that the edit box fills the rest of the width of the parent.
What does layout_weight do?
In a LinearLayout, it specifies how to assign the remaining space across different views. Whatever space each view needs (based on wrap_content, explicit width, etc.) would be used first, then any extra space that is available will be assigned to all the views in proportion to their weights.See here for more details.

No comments:
Post a Comment