HorizontalScrollView - calculate break position after start

With HorizontalScrollView, how to determine when scrolling stops after a user declines a view? Or, alternatively, how do I know what position the scroll will be when it stops (then I could use it with onScrollChanged).

I have inherited HorizontalScrollView. I would like the view to look natural when the user interacts with it, but when it stops to refresh some of its child views - if I do this while the scroll view causes slight delays during the scroll.

thank

+3
source share
2 answers

HorizontalScrollView, , scrollX . :

public class CustomMCSDHorizontalScroll extends HorizontalScrollView {

    private Runnable scrollerTask;
    private int initialPosition;
    private int newCheck = 100;


    public interface onScrollStopedListner{
        void onScrollStoped();
    }

    private onScrollStopedListner onScrollStoped;

    public CustomMCSDHorizontalScroll(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        scrollerTask = new Runnable() {
            @Override
                public void run() {
                    // TODO Auto-generated method stub
                    int newPosition = getScrollX();

                    if ( initialPosition - newPosition == 0 ) {
                        if ( onScrollStoped != null ) {
                            onScrollStoped.onScrollStoped();
                        }
                    } else {
                        initialPosition = getScrollX();
                        CustomMCSDHorizontalScroll.this.postDelayed(
                            scrollerTask, newCheck);
                    }

                }
        };
    }

    public void setOnScrollStopListner (CustomMCSDHorizontalScroll.
            onScrollStopedListner listener) {
        onScrollStoped = listener;
    }

    public void startScrollerTask(){
        initialPosition = getScrollX();
        CustomMCSDHorizontalScroll.this.postDelayed(scrollerTask, newCheck);
    }

}

ontouch():

@Override
public boolean onTouch(View v, MotionEvent event) {

    switch (v.getId()) {
        case R.id.mHorizontalScrollViewMain:
            if (event.getAction() == KeyEvent.ACTION_UP) {
                hsvUpperTab.startScrollerTask();
            }
            break;
        case R.id.mHorizontalScrollViewSub:
            if (event.getAction() == KeyEvent.ACTION_UP) {
                hsvLowerTab.startScrollerTask();
            }
        default:
            break;
    }
    return false;
}

onScrollStop():

hsvLowerTab.setOnScrollStopListner(new onScrollStopedListner() {
    @Override
    public void onScrollStoped() {
        // TODO Auto-generated method stub
        getLowerTabScrolled(hsvLowerTab.getScrollX());
    }
});

hsvUpperTab.setOnScrollStopListner(new onScrollStopedListner() {
    @Override
    public void onScrollStoped() {
        // TODO Auto-generated method stub
        getUpperTabScrolled(hsvUpperTab.getScrollX());
    }
});
+3

scroller .

.

  • HorizontalScrollView onTouchEvent, onInterceptTouchEvent false.
  • OnGestureListener .
  • onFling

    fling (int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY)

  • :

getFinalX() getFinalY()

isFinished() , , .

+2

All Articles