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
What I do is in the onCreate for the activity, measure the EditText first then apply its maxWidth.
You can do so using code similar to the following:
EditText someedittext = (EditText)findViewById(R.id.sometextview);
someedittext.setMaxWidth(someedittext.getWidth());
The correct way to do this would be to set the android:minWidth and android:maxWidth equal to the width you want. This way you will not have to adjust your layout to use the android:layout_weight.
For example if you want your EditText to always be 80 density pixels no matter how many characters you type in use the following:
android:minWidth="80dp"
android:maxWidth="80dp"
The chosen solution works, but let me add a little complement:
if you use
android:layout_weight="0.15"
(the value is not important)
then
android:layout_width="0dp"
if the LinearLayout
is Horizontal
or
android:layout_height="0dp"
if the LinearLayout
is Vertical.
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.
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 maxLines
setting to 1 too.
You need to add android:imeOptions to prevent this behavior.