4

I have an edittext that is 80% of the screen across and a button that should take the remaining 20%, but when text is entered into the box or removed the edittext grows and shrinks.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">

   <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:weightSum="100">

      <Button
         android:id="@+id/people_relationFilterB"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="20" />

      <EditText
         android:id="@+id/people_searchBoxET"
         android:text="Search Known"
         android:singleLine="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="80" />
   </LinearLayout>

   <ListView
     android:id="@+id/people_listLV"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content" />

</LinearLayout>

Any Clues? Thanks!

3 Answers 3

15

Try to set android:layout_width="0dp"

1
  • 1
    To clarify: This applies to the Button and EditText widgets, not the LinearLayout(s). Feb 16, 2012 at 8:43
4

I believe your issue is you are setting the layout width of the EditText as wrap_content. I had this problem when I started Android development as well. You are essentially telling Android that you want your EditText to size itself to fit the text you entered.

The solution is to set the layout width as fill_parent and then if needed wrap a LinearLayout around it to contain the size.

0

Try to set EditText

android:layout_width="0dp"
android:layout_weight="1"
1
  • 1
    while this may be a correct answer, it is not very helpful. Would you mind adding some explanation?
    – GameDroids
    Sep 18, 2014 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.