0

I have a ScrollView, and it's working, I'm able to get to the bottom and back to the top. The problem is that when the user remove the finger from the screen, the scrolling stops immediately . It was supposed to be smoother and not tiring to get to the bottom. Can anyone help me?

Here's my code:

XML:

<ScrollView
    android:id="@+id/home_content_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/color_background_default"
    android:fadingEdgeLength="@dimen/app_fading_edge_length" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_background_default"
        android:orientation="vertical"
        android:padding="@dimen/app_content_padding" >

        <!-- Lots of different components here -->
    </LinearLayout>
</ScrollView>

I tryed to do scrollView.setSmoothScrollingEnabled(true); but that didn't work either.

Another thing, I show some content that are fetched asynchronously after the main content of the scrollView is rendered. Some of them are images and may affect the total height of the scroll... Thinking about that I did

scrollView.refreshDrawableState(); scrollView.requestLayout();

That did not work at all...

Thalescm
  • 155
  • 1
  • 10

3 Answers3

1

Today, I faced a similar problem. In my particular case, I had a RecyclerView inside ScrollView. After experimenting for a while, I found that there was nothing wrong with the ScrollView. It was the RecyclerView inside responsible. SO I did this:

myRecyclerView.setNestedScrollingEnabled(false); /** THIS is the line that makes Recyclerview inside scrollview to scroll smoothly!*/

Perhaps you should check out other elements. Reference

Qazi Fahim Farhan
  • 2,066
  • 1
  • 14
  • 26
0

If you don't like how Android handles it when you remove your finger to stop scrolling, you could overload that logic like so:

ScrollView myScrollView = (ScrollView) findViewById(R.id.my_scrollview_id);
myScrollView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (mVelocityTracker == null) {
                    mVelocityTracker = VelocityTracker.obtain();
                } else {
                    mVelocityTracker.clear();
                }
                mVelocityTracker.addMovement(event);
                break;
            case MotionEvent.ACTION_MOVE:
                mVelocityTracker.addMovement(event);
                mVelocityTracker.computeCurrentVelocity(1000);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                ((ScrollView)v).smoothScrollBy(0, (int) (mVelocityTracker.getYVelocity()*myScalarMultiple));
                return true;
            }
            return false;
        }

    });

We return "false" for ACTION_DOWN and ACTION_MOVE because we just want to impact the velocity tracker, not consume the touch events to the ScrollView. You'd have to experiment also with the value of myScalarMultiple to get the results you like.

EricaCooksey
  • 239
  • 1
  • 12
  • I don't know why, but it's not entering in that function, so I don't if this will work or not. If I manage to solve why, and it works, I will accept your answer. But thanks anyway! – Thalescm Jul 07 '14 at 20:57
  • Please post your code; I ran this source on my end and it worked fine. – EricaCooksey Jul 07 '14 at 23:46
0

wrap scrollview inside a layout, it will work smoothly

A sample code is given below for reference

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

        </LinearLayout>
    </ScrollView>
</LinearLayout>
Eldhopj
  • 2,703
  • 3
  • 20
  • 39