EditText will not fill the remaining space

So, I have this β€œTo” text box, an edittext for entering a contact and a search button for finding contacts on one line. The text image and button are in a good place, but the problem is that the edittext is small, I want it to take up all the other spaces. Here is the code:

<RelativeLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:paddingTop="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="To: " android:textColor="#000000" android:paddingTop="10dp" android:layout_toLeftOf="@+id/editText_recipient" android:layout_alignParentLeft="true" android:layout_marginLeft="10dp"/> <EditText android:id="@+id/editText_recipient" android:layout_height="wrap_content" android:layout_width="wrap_content" android:hint="Enter Number" android:inputType="number" android:textSize="12sp" android:layout_toLeftOf="@+id/button_recipient_picker" android:layout_marginLeft="5dp"/> <Button android:id="@+id/button_recipient_picker" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Browse .." android:layout_alignParentRight="true" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:onClick="doLaunchContactPicker"/> </RelativeLayout> 
+7
source share
2 answers
 <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:paddingTop="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="To: " android:textColor="#000000" android:paddingTop="10dp" android:layout_marginLeft="10dp"/> <EditText android:id="@+id/editText_recipient" android:layout_height="wrap_content" android:layout_width="wrap_content" android:hint="Enter Number" android:inputType="number" android:textSize="12sp" android:layout_marginLeft="5dp" android:layout_weight="1" /> <Button android:id="@+id/button_recipient_picker" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Browse .." android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:onClick="doLaunchContactPicker"/> </LinearLayout> 

use this layout, I converted your layout to linear (default by default). and added layout_weight to editText, it will take up the remaining space.

+17
source

For those who need an answer to this question and to solve this problem without giving an alternative, the answer is quite simple. You need to tell each control where to position each other and apply it to the control that should take the available android:layout_width = "match_parent" space android:layout_width = "match_parent" , although in LinearLayout this will cause all other controls to align out of the screen, in RelativeLayout it works great

 <RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:paddingTop="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="To: " android:textColor="#000000" android:paddingTop="10dp" android:layout_toLeftOf="@+id/editText_recipient" android:layout_alignParentLeft="true" android:layout_marginLeft="10dp"/> <EditText android:id="@+id/editText_recipient" android:layout_height="wrap_content" android:layout_width="MATCH_PARENT" android:hint="Enter number" android:inputType="number" android:textSize="12sp" android:layout_toLeftOf="@+id/button_recipient_picker" android:layout_marginLeft="5dp"/> <Button android:id="@+id/button_recipient_picker" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Browse .." android:layout_alignParentRight="true" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:onClick="doLaunchContactPicker"/> </RelativeLayout> 
+2
source

All Articles