1
votes

I have a TableLayout with a number of TableRows. Each row contains two TextViews laid out horizontally. The TextViews have fixed widths. The background of each is colored differently; the left is grey and used as a label, and the right is white and contains a value. However, the content of both is dynamic. For any given row, the content of either might be large enough to warrant wrapping to a new line.

Because the backgrounds are colored differently, I need each TextView to match its parent row in order for the colors to fill the view correctly. However, if I set a TextView's layout_height to match_parent then the TextView doesn't wrap to a newline if the content is large. In the following screenshot, there is more to the labels than just the first word that is shown:

screenshotOne

On the other hand, if I set a TextView's layout_height to wrap_content, then if the sibling TextView's height is larger (and therefore the TableRow's height), then the first TextView's background doesn't fill the space created:

screenshotTwo

So, I want both TextView's in a TableRow to wrap to a newline if necessary, but also for the backgrounds of each to fill the space in the TableRow at all times.

1

1 Answers

0
votes

I found a solution to my problem:

  1. I set the background of each TableRow to the gray (label) color, and gave it the bottom border.
  2. I left the label TextViews' backgrounds blank, defaulting them to the TableRows' gray background.
  3. I set the backgrounds of the value TextViews to be white, overlaying the TableRows' background, but the borders can still be seen.
  4. I set the label TextViews' layout_width and layout_height to wrap_content
  5. I set the value TextViews' layout_width to wrap_content, but their layout_height to match_parent

This worked for every row except the email, where the value always took up more space than the label. So for that particular row I changed the layout_height of the value TextView to wrap_content.