如何滚动到TextView文本中的特定符号

时间:2016-07-04 07:38:22

标签: android textview android-scrollview

我有TextView嵌套ScrollViewTextView包含HTML格式的文本。用户可以更改文本的大小。

案文分为几部分:

Part1 till <br> Part2 till , Part3 till <br>

每个部分都有不同的长度。

如何滚动到Part2 till ,

Look this

有例子......

tView = (TextView)findViewById(R.id.your_text_view);
tView.setMovementMethod(new ScrollingMovementMethod());

// tView.append(text + "\n");
tView.scrollTo();
final Layout layout = tView.getLayout(); // <-- THIS RETURN null 
if(layout != null){
int scrollDelta = layout.getLineBottom(tView.getLineCount() - 1) - tView.getScrollY() - tView.getHeight();
     if(scrollDelta > 0)  tView.scrollBy(0, scrollDelta);
}

0 个答案:

没有答案
相关问题