auto-scrolling TextView in android to bring text into view

前端 未结 13 1726

I have a TextView that I\'m dynamically adding text to.

in my main.xml file I have the properties set to make my max lines 19 and scrollbar

13条回答
  •  庸人自扰
    2020-11-28 05:40

    (2017) using Kotlin:

    // you need this to enable scrolling:
    mTextView.movementMethod = ScrollingMovementMethod()
    // to enable horizontal scrolling, that means word wrapping off:
    mTextView.setHorizontallyScrolling(true)
    ...
    mTextView.text = "Some long long very long text content"
    mTextView.post {
         val scrollAmount = mTextView.layout.getLineTop(mTextView.lineCount) - mTextView.height
         mTextView.scrollTo(0, scrollAmount)
    }
    

    This works file for me

提交回复
热议问题