美文网首页Android知识Android开发
TextView 添加文字后自动滚动到最后添加

TextView 添加文字后自动滚动到最后添加

作者: satisfying | 来源:发表于2018-03-07 20:02 被阅读0次
  1. 首先给TextView添加滚动条

    android:scrollbars="vertical"

  2. 设置滚动
    textview.setMovementMethod(new ScrollingMovementMethod());

  3. 添加文字并滚动

int line = textview.getLineCount();
 if (line > 11) {//超出屏幕自动滚动显示(11是当前页面显示的最大行数)
       int offset = textview.getLineCount() * textview.getLineHeight();
       textview.scrollTo(0, offset - textview.getHeight() + textview.getLineHeight());
    }

相关文章

网友评论

    本文标题:TextView 添加文字后自动滚动到最后添加

    本文链接:https://www.haomeiwen.com/subject/mnssfftx.html