auto-scrolling TextView in android to bring text into view

前端 未结 13 1702

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:42

    to avoid creating dummy scroolview I did

    int top_scr,rec_text_scrollY;
    top_scr=(int)rec_text.getTextSize()+rec_text.getHeight();
    rec_text_scrollY=rec_text.getLineBounds(rec_text.getLineCount()-1, null)-top_scr;
        //repeat scroll here and in rec_text.post. 
        //If not scroll here text will be "jump up" after new append, and immediately scroll down
        //If not scroll in post, than scroll will not be actually processed
    if(rec_text_scrollY>0)rec_text.scrollTo(0, rec_text_scrollY);
    rec_text.post(new Runnable(){
        @Override
        public void run() {
            if(rec_text_scrollY>0)rec_text.scrollTo(0, rec_text_scrollY);
        }                   
    });
    
    0 讨论(0)
提交回复
热议问题