Scroll scroll detection

I am trying to detect when ScrollView has finished scrolling, so I can slightly change its position. Before I used ACTION_UP to determine when the user raised his finger, but then I realized that this would not allow me to use “flinging”, as this would change the scroll before it was finished.

Is there any way to detect when ScrollView has completed scrolling? Or determine its scroll state, such as ListView?

Any other ideas on how to implement this?

Thank.

+5
source share
2 answers

I implemented the solution based on Jourbac's comment.

Hi

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ScrollView;

public class MyScrollView extends ScrollView {

    private static final int WHAT = 1;

    class MyHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(!hasMessages(WHAT)) {
                Log.i("TestScroll", "Last msg!. Position from " 
                                    + msg.arg1 + " to " + msg.arg2);                
            }
        }
    }

    private Handler mHandler = new MyHandler();

    public MyScrollView(Context context) {
        super(context);
    }

    public MyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        final Message msg = Message.obtain();
        msg.arg1 = oldt;
        msg.arg2 = t;
        msg.what = WHAT;
        mHandler.sendMessageDelayed(msg, 500);
    }

}
+3
source

, ScrollView, , MyScrollView ScrollView.

ScrollView, ; ( super)

, ScrollView , ; , , scoll, ... scrollTo().

, , , . , , , , , .

+1
source

All Articles