Adam L.
Adam L.

Reputation: 394

Layout Form with Long Labels

I am having some difficulty with an Android layout problem. I am trying to make a form for users to fill out. This form is defined programmatically (from a server-provided configuration over which I have no control) and thus I must implement it programmatically. The form has several different field types, but for simplicity we can assume they are all simple text fields (EditText).

I currently have the form implemented as a vertical LinearLayout. For each field I have a horizontal LinearLayout that contains a TextView for a field label and an EditText for the user to enter a value for the field. I have the EditText set to fill the width using LinearLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT).

This works well when the TextView label is short, but when it is long it causes the EditText to be very small and makes it hard for the user to enter a value. Ideally I would like the EditText to be at least half the width of the screen with the TextView label wrapping if necessary. I've tried a TableLayout with TableRows but I still had difficulty. I would also rather not force a grid and thus waste the space on the lines with short labels (assuming the other requirements are met I'm flexible on this). I would have tried something like a FlowLayout to force the EditText to wrap onto the next line but it's not supported on Android.

Any suggestions for how I can make this work better? XML-based solutions will be accepted assuming I can port them to a programmatic approach. I would also like to make this as flexible with respect to screen size and orientation as possible, so this means avoiding hard-coding any widths.

Thanks in advance.

Upvotes: 3

Views: 744

Answers (1)

Cheryl Simon
Cheryl Simon

Reputation: 46844

Try playing around with layout weights. You should be able to tell your two items to each take up half the screen, for example, by setting the width=0 and layout_weight=1 for both.

Upvotes: 1

Related Questions