Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText wont fill up the remaining space

So i have this textview "To", an edittext to input the contact and a search button to search for contacts all in one line. The textview and button are all in good place but the problem is the edittext is small, i want it occupy all the remaining spaces. Here's 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>
like image 995
kev Avatar asked Oct 26 '11 04:10

kev


1 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 (horizontal default). and added a layout_weight to editText, it will occupy the remaining space.

like image 51
Yashwanth Kumar Avatar answered Nov 05 '22 03:11

Yashwanth Kumar