2

I have a ScrollView with a TextView inside of it. I want to make sure that the app automatically scrolls down to the bottom each time text is entered into the TextView.

    <ScrollView
    android:id="@+id/textScroll"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/gridLayout"
    android:layout_marginBottom="100dp"
    android:fillViewport="true">

    <TextView
        android:id="@+id/numerTV"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:textSize="60sp"/>
</ScrollView>

So this is the .xml file. I have tried a lot of different solutions that I've found around here:

    textScroll.post(new Runnable() {
        @Override

        public void run() {

            textScroll.scrollTo(0, textScroll.getBottom());
            //textScroll.post(new Runnable() {
            //public void run() {
            //    textScroll.fullScroll(View.FOCUS_DOWN);
            // }
            // });
            Log.d("Scroll","Scrolling");

        }
    });

Also tried to set autoscroll via xml but nothing works.

Any ideas what I'm doing wrong? How come the "solution" above works for so many but not for me?

Help much appreciated!

Elimination
  • 25
  • 1
  • 7
  • You have your `TextView` height set to 70dp. If you don't set it to `wrap_content`, it never gets big enough to scroll. And for `scrollTo()`, I think you want the height (not bottom) of the `TextView` (not the `ScrollView`) – kris larson Jun 17 '16 at 20:36
  • THANK YOU! Thou art a god amongst men. Been driving me crazy! – Elimination Jun 17 '16 at 20:39

1 Answers1

0

You can make your ScrollView move to the last position by using smoothScrollTo(x,y).

Then, you can get the arguments from the ScrollView

ScrollView sv = (ScrollView) findViewById(R.id.textScroll);
sv.smoothScrollTo(sv.getX(), sv.getY());
rupinderjeet
  • 2,984
  • 30
  • 54
Collins
  • 145
  • 2
  • 15
  • It didn't fix it, Kris Larson's answer did. But this did give me a smoother scroll so I still like it :) Combined this and Kris' solution and got smooth scroll every time text is entered. Thanks – Elimination Jun 17 '16 at 20:42