0

I am having a framelayout with two textviews where the second textview has to follow after the first textview. There is too much of space between the two text views as the width depends on the character width of the string. How do i calculate the width of the string or the width of each characters in the string so that i could place the second text view after the first.

SpannableString strUserName = new SpannableString(String.format(
            "%" + Name().length() + "s", "")
            .replace("", " ")
cavallo
  • 4,414
  • 9
  • 39
  • 61
  • 1
    Possible duplicate: http://stackoverflow.com/questions/3630086/how-to-get-string-width-on-android – JesperB May 29 '12 at 12:57
  • JesperB i already refered that but did not help .. – cavallo May 29 '12 at 13:04
  • Have a look at this question. While the question isn't exactly the same as yours, the answer is exactly what you're looking for: http://stackoverflow.com/questions/6232541/android-measuretext-return-pixels-based-on-scaled-pixels – Aleks G May 29 '12 at 13:32
  • @cavallo what was the problem with `getTextBounds()` answer? Also, how about putting the textViews in `LinearLayout`? – Pēteris Caune May 29 '12 at 13:37
  • i get the width in pixel as 47 which moves the second text view to the next row. but i want to place it after the first text view. and the textviews are already in the linear layout. – cavallo May 30 '12 at 05:22
  • A horizontal LinearLayout doesn't move its elements to next row. Do you have `orientation="horizontal"` set on it? Please post your layout XML, code and screenshot of how it looks in action. – Pēteris Caune May 30 '12 at 10:53

0 Answers0