views:

23

answers:

1

Hi, I've had a good search for this on here and can't find a solution.

I have a TextView in a RelativeLayout which contains an integer number. The number will range between 1 and 99 - can anyone tell me how to size the TextView so that its width is always the width of the string "99" even if it only contains "1"?

I need this because the positions of the components to the right of this TextView depend on its width, so all are position depending on how many digits the TextView contains.

I don't mind if this is done in XML or code - I just want to avoid having to set the width of a TextView in pixels!

Thanks for any possible solutions; Please ask if I've missed out any important info!

A: 

You can give it an absolute width using android:layout_width, just put in a string like "14.5sp" instead of FILL_PARENT.

BrennaSoft
Hi, thanks for your answer. However, as I mentioned, I want to set the width of the TextView based on the width of the string it can contain rather than an absolute width in pixels, for obvious reasons.
If This Is Art