How to scroll to bottom in a ScrollView on activity startup

后端 未结 9 990
Happy的楠姐
Happy的楠姐 2020-11-27 14:38

I am displaying some data in a ScrollView. On activity startup (method onCreate) I fill the ScrollView with data and want to scroll to the bottom.

I tried to use

相关标签:
9条回答
  • 2020-11-27 15:34

    Put the following code after your data is added:

    final ScrollView scrollview = ((ScrollView) findViewById(R.id.scrollview));
    scrollview.post(new Runnable() {
        @Override
        public void run() {
            scrollview.fullScroll(ScrollView.FOCUS_DOWN);
        }
    });
    
    0 讨论(0)
  • 2020-11-27 15:35

    It needs to be done as following:

        getScrollView().post(new Runnable() {
    
            @Override
            public void run() {
                getScrollView().fullScroll(ScrollView.FOCUS_DOWN);
            }
        });
    

    This way the view is first updated and then scrolls to the "new" bottom.

    0 讨论(0)
  • 2020-11-27 15:36
     scrollView.postDelayed(new Runnable() {
            @Override
            public void run() {
                scrollView.fullScroll(ScrollView.FOCUS_DOWN);
            }
        },1000);
    
    0 讨论(0)
提交回复
热议问题