如何将 ScrollView 滚动到文本中的某个位置

Ere*_*nfo 5 android scrollview textview

我有一个带有 TextView 的 ScrollView,我想将它滚动到某个段落,就像 HTML 中的锚点(例如 page.html#paragraph_id)。

有人知道这样做的方法吗?

谢谢!

Sil*_*ler 1

尝试使用scrollTo方法更多信息

检查以下代码

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");
    }
}); 
Run Code Online (Sandbox Code Playgroud)