1

Not sure it is clear from this question title what I mean, so here are details.

What I'd like to achive is simple layout with two TextView controls aligned horizontally one after another. First TextView could probably contain several lines of text, second TextView will contain only 1 number.

Second TextView should always have widht as much as it is required to show its content, aligned to the right and height should be equal to height of first TextView so I can show data vertically centered. First TextView should take remaining space (for width) and stretch vertically as needed.

Example 1:

 --------------------------------- |Small Text. 123| --------------------------------- 

Example 2:

 --------------------------------- |Long Text starts here .... | |... continues here ....... 123| |... and finishes here .... | --------------------------------- 

LinearLayout with horizontal orientation is not good here since it places controls from left to right. While in this case I need first set wrap_content to second TextView and then fill_parent to first TextView.

Playing with RelativeLayout I also could not get described layout.

I could not use layout_weight approach here since I do not know length of data in second TextView: in one case it could be 1 character, in another - 8 characters. So in 1 character case I will have unused space.

So, do I have chance to build such layout?

1
  • Have you tried using a TableLayout for this? Commented Nov 30, 2011 at 12:44

2 Answers 2

4

A layout like the following should do the trick for you:

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:singleLine="false" android:text="TextView" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center_vertical|right" android:text="TextView" /> </LinearLayout> 
Sign up to request clarification or add additional context in comments.

1 Comment

use layout_width = "match_parent" to the view wherever use layout_weight attribute.
-1

here will be useful to use the minWidth and maxWidth properties.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.