views:

3789

answers:

4

I have an EditText and a button set next to each other on the same horizontal line. It looks great, except when the user enters a lot of text, the EditText is resized, and the button is squished.

I have both EditText and Button set to layout_width="wrap_content". "fill_parent" messes up the layout, and I don't want to use absolute sizes if I don't have to - the way it is now looks great in both landscape and portrait, I just don't want the EditText to resize.

Thanks for any suggestions!

My layout:

      <TableLayout android:id="@+id/homelayout"
   android:layout_width="fill_parent" android:layout_height="fill_parent">
   <TableRow>
   <TextView android:id="@+id/labelartist"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:text="Find artists:" />
   </TableRow>
   <TableRow>
    <EditText android:id="@+id/entryartist"
     android:layout_width="wrap_content" android:layout_height="wrap_content"
     android:background="@android:drawable/editbox_background"
     android:singleLine="true"
     android:editable="true"
     android:layout_weight="6"
     android:padding="5px"
      />

    <Button android:id="@+id/okartist" android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentRight="true" android:layout_marginLeft="10dip"
     android:layout_weight="1"
     android:text="Search" />
   </TableRow>
  </TableLayout>
A: 

Give EditText a maxWidth. That should stop it from resizing beyond the width you provided. Also, if you want it to be contained within 1 line set the max lines setting to 1 too.

Prashast
Thanks - I don't really want to hardcode a specific maxWidth, since it wouldn't be the same for different orientations or screen sizes.
alex_c
+5  A: 

For EditText use
android:layout_width="0dp" - not required but preferred.
android:layout_weight="1"

And for Button dont specify android:layout_weight

bhatt4982
Thanks - that did the trick!What does the "0dp" signify for the width? That it should take up all the available space?
alex_c
yes, it will. The layout_weight tag will do that.
bhatt4982
A: 

I had a similar problem, but I couldn't get the above to work. What I did, is take in the text from EditText box and then format it down to the max size that my screen could handle. When I save this off to the DB, I will save it as display Text and original text.

If you go to this page I put a longer explanation.

A: 

Just use:

android:layout_width="fill_parent"

for both EditText and Button. It will also work set for EditText but it is better to have it on both.

Kamen