Long Label Layout Form

I'm having difficulty with the Android layout problem. I am trying to create a form for users to fill out. This form is determined programmatically (with a configuration provided by the server, which I do not control), and therefore I must implement it programmatically. A form has several different types of fields, but for simplicity we can assume that they are all plain text fields (EditText).

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

This works well when the TextView label is short, but when it is long, this makes the EditText very small and makes it difficult for the user to enter a value. Ideally, I would like EditText to be at least half the width of the screen, wrapping the TextView label if necessary. I tried TableLayout with TableRows, but I still had difficulties. I would also prefer not to create a grid and thus waste space on lines with short labels (subject to other requirements, I am flexible about this). I would try something like FlowLayout to get EditText to turn to the next line, but it is not supported on Android.

Any suggestions on how I can improve this work? XML-based decisions will be made if I can port them to a programmatic approach. I would also like to make this as flexible as possible with respect to screen size and orientation, so this means that you avoid hard coding of any width.

Thanks in advance.

+3
source share
1 answer

Try playing with the scale weights. You should be able to say that your two elements for each occupy half the screen, for example, setting width = 0 and layout_weight = 1 for both.

+1
source

Source: https://habr.com/ru/post/1784631/


All Articles