2

I'm looking to place text in a TextView with a fixed width, and which can be spread over two lines, but what I want is to do is to place as much of the text towards the bottom as possible. For example, this is current what happens:

 The quick brown fox jumps over 
 the lazy dog

But what I want to happen is:

 The quick brown
 fox jumps over the lazy dog

Does anyone have any ideas how, if possible, this might be achieved using just one TextView?

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
Fifer Sheep
  • 2,900
  • 2
  • 30
  • 47

1 Answers1

1

I agree with Aleks that there probably isn't a built-in solution for this. You'll probably need to do some clever manipulations. One possible solution might be to create your own TextView that takes the String and calculates where to split the String and draw it accordingly.

You can use the following code (reference here) to get the width of a String if it were to be rendered in a TextView:

Paint textPaint = textView.getPaint();
float width = textPaint.measureText(string);

You could then use information about the width of your TextView to calculate where to "chop" the String and draw it. It's a solution that'll need perfecting, but that's what I would try.

Community
  • 1
  • 1
Brian
  • 7,955
  • 16
  • 66
  • 107