Scrollview not scrolling down completely

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 is appended to the screen. I’m using

 ScrollView my_scrollview = (ScrollView) findViewById(R.id.scroller);
 my_scrollview.fullScroll(ScrollView.FOCUS_DOWN);

This seems to work, although for some reason, because the keyboard is usually on screen while chatting, when the scrollview scrolls down it doesn’t completely – the newest textview added is not displayed (you’ll have to manually scroll down to the newest one). How do I go about fixing this?

  • Prevent onPause from trashing OpenGL Context
  • CoordinatorLayout + TabView + AnimateView(From Top)
  • Implicit intent to uninstall application?
  • Set color of TextView span in Android
  • Remove Android App Title Bar
  • Android PendingIntent take you to an already existing activity?
  • ActionBar setBackgroundDrawable() nulling background from Thread/Handler
  • How to restart adb from root to user mode?
  • Android 4.2.2 - adb offline, even after SDK upgrade
  • Android Unit Test with Retrofit and Mockito
  • Android get free size of internal/external memory
  • Change Elevation of ActionBar by theme
  • 2 Solutions collect form web for “Scrollview not scrolling down completely”

    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!

    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.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.