The default weight for all views is 0, so if you specify any weight value greater than 0 to only one view, then that view fills whatever space remains after all views are given the space they require. So, to fill the remaining space in your layout with the EditText
element, give it a weight of 1 and leave the button with no weight.
<EditText android:layout_weight="1" ... />
In order to improve the layout efficiency when you specify the weight, you should change the width of theEditText
to be zero (0dp). Setting the width to zero improves layout performance because using "wrap_content"
as the width requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.
<EditText android:layout_weight="1" android:layout_width="0dp" ... />
Figure 3 shows the result when you assign all weight to the EditText
element.