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>

  • SSL Client authentication in Android 4.x
  • Android N - how to check if apk is signed with schema v2
  • Action Bar Back Button is not showing in Android
  • Is local storage for a Phonegap app on an Android device separate from the built in browser?
  • Achartengine: Inserting dates as X-values in
  • EditText and InputFilter cause repeating text
  • Related posts:

    Should accessing SharedPreferences be done off the UI Thread?
    Start Activity Using Custom Action
    Dagger 2 Build IllegalArgumentException compileDebugJavaWithJavac
    Android Handlers - inter-thread communication
    Attach TextView to RecyclerView
    getChildView not being called
  • My ListView backgrounds go black during scrolling - how to fix?
  • Cannot lower case button text in android studio
  • Share Wifi credentials via NFC tag without special apps
  • Android : How to put cross icon on top of the autocomplete textView
  • Navigation Drawer to switch activities instead of fragments
  • Using ADB locally on device (loopback) shows no devices
  • 2 Solutions collect form web for “EditText wont fill up the remaining space”

    <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.

    For those who need an answer to this and to resolve this post without giving an alternative, the answer is fairly simple.
    You need to tell every control where to position according to each other and apply to the control which should take available space android:layout_width = "match_parent" even though in a LinearLayout, this would push every other control aligned out of the screen, in a RelativeLayout it works perfectly

    <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>
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.