I want to scroll my TextView to make visible a specific position in the text. How can I do that? I tried bringPointIntoView (int offset) but without success.
Source
Does adding a movement method to the text view solve the problem?
textView.setMovementMethod(new ScrollingMovementMethod());
Just FYI for anyone else with the same problem, on a listView
with large listItems
, the overloaded bringPointIntoView
can be passed a ListView
instead of a ScrollView
and use the ScrollTo
method instead of smoothScrollTo
.
For those who have the same problem, I finally made my own implementation of bringPointIntoView:
public static void bringPointIntoView (TextView textView,
ScrollView scrollView, int offset)
{
int line = textView.getLayout ().getLineForOffset (offset);
int y = (int) ((line + 0.5) * textView.getLineHeight ());
scrollView.smoothScrollTo (0, y - scrollView.getHeight () / 2);
}
Don't hesitate if you have a better solution.