Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent an EditText from resizing itself when the user is typing?

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.

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:layout_weight="6"             android:background="@android:drawable/editbox_background"             android:editable="true"             android:padding="5px"             android:singleLine="true" />         <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> 
like image 303
alex_c Avatar asked Sep 11 '09 03:09

alex_c


People also ask

What is the function of setting autoText attribute in EditText?

android:autoText If set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors.

How do you make EditText read only?

The most reliable way to do this is using UI. setReadOnly(myEditText, true) from this library. There are a few properties that have to be set, which you can check out in the source code.

How do I edit EditText Uneditable?

If you want your disabled EditText to look the same as your enabled one, you should use android:enabled="false" in combination with android:textColor="..." . Show activity on this post. Used this if you have an icon to be clickable, this works for me.


1 Answers

For EditText use

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

And for Button dont specify android:layout_weight

like image 84
bhatt4982 Avatar answered Sep 19 '22 10:09

bhatt4982