Andy
Andy

Reputation: 10830

How to keep EditText from breaking to the next line when width does not match_parent?

I am trying to fit two EditTexts horizontally. What I am trying to accomplish is make the text keep scrolling right without the EditText extending in anyway when there is no more space in that specific EditText. This happens when the EditText is set to match_parent (width), but when I set an actually width or wrap_content, it breaks to the next line. Not the behavior I am hoping for. Any ideas?

Upvotes: 1

Views: 967

Answers (2)

aamit915
aamit915

Reputation: 519

If I understood your question correctly, you're saying you want the edit text to be a single line each? If so, have you tried using the xml attribute

android:singleLine

Or you can accomplish the same thing with:

setSingleLine() //called on the edit text

I just tested it out with 2 edit texts in a horizontal linear layout set to 100dp width each and I think it accomplishes the behavior you want.

Upvotes: 2

Mike Mackintosh
Mike Mackintosh

Reputation: 14237

You can try this:

Set both to fill_parent and layout_weight=1. This will align them side by side.

Upvotes: 0

Related Questions