I have a ScrollView with a TextView inside it, and I'd like to scroll it to a certain paragraph, just like anchors in HTML (e.g page.html#paragraph_id).
Does anybody know a way to do it?
Thanks!
Try using scrollTo
method More Info
check with follow code
TextView tv = (TextView)findViewById(R.id.textView);//my text view
ScrollView sv = (ScrollView) findViewById(R.id.scrollView);//my scrollview
String log ="a Very long text";
tv.setText(log);
sv.post(new Runnable() {
public void run() {
sv.scrollTo(0, "value till you want to scroll");
}
});
Really a very intresting question. I am also tyring to do so.
What I have done is an idea to map textview - lines to scrollview coordinates.
what you can do is get the device-display size - in pixels.
and a line height of the textview by- textview.getLineheight(); and calculate the line
coordinates and map it to the scrollview
As I said I am also trying to do this. I am currently working on the same.
If I find some code working I will let you know.
Its lot of work to do because android os does not provide such kind of scroll you (or I) want
OR you can have textview for each line and use this code mScrollView.scrollTo(0, your_text_view_with_the_line.getBottom());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With