Scrollview not scrolling down completely

后端 未结 3 840
青春惊慌失措
青春惊慌失措 2021-01-04 08:42

I\'m building a chat-like application that displays text the user inputs to the screen using a scrollview. What I\'m doing is auto-scrolling the scrollview down as more text

相关标签:
3条回答
  • 2021-01-04 09:08
            @Override
            public void onClick(View v) {
    
                scview_ashora = findViewById(R.id.scview_ashora);
                scview_ashora.fullScroll(ScrollView.FOCUS_DOWN);
    
                scview_ashora.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //replace this line to scroll up or down
                        scview_ashora.fullScroll(ScrollView.FOCUS_DOWN);
                    }
                }, 1000000L);
    
    
            }
        });
    
    0 讨论(0)
  • 2021-01-04 09:19

    I looked around, and found that some other people have run into the same problem.

    I solved this problem using this piece of code:

    final ScrollView scrollView = (ScrollView) findViewById(R.id.scroll_view);
    scrollView.post(new Runnable() {
        public void run() {
            scrollView.fullScroll(View.FOCUS_DOWN);
        }
    });
    

    Hopefully this can help somebody out there!

    0 讨论(0)
  • 2021-01-04 09:19

    Its late but may help some one with this issue.. It takes around 200 miniseconds to add the last element and update it for a scrollView so this will surely work.

    void scrollDown()
    {
        Thread scrollThread = new Thread(){
            public void run(){
                try {
                    sleep(200);
                    ChatActivity.this.runOnUiThread(new Runnable() {
                        public void run() {
                            myScrollView.fullScroll(View.FOCUS_DOWN);
                        }    
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        scrollThread.start();
    }
    

    Just call scrollDown(); after adding element to scrollView.

    0 讨论(0)
提交回复
热议问题