Android how to listen ListView scrolling offset problem

Today I wanted to implement the UI looks like Google plus app in both Android and IOS.

One thing came out is that ListView and bottom menu.

From Google Plus that bottom menu will slidedown when User scrolling the listview down and slideup when user scrolling the listview up.

So the question is how to listen the listview scrolling up and down.

First , there is no this api to listen how much listview scrolled by.

Second, I tried the onInterceptTouchEvent in my customized ListView. It only works at first several touchevents. Then I checked the source codes of ListView and AbsListView.

in function :


private boolean startScrollIfNeeded(int y){
    ...
    if (overscroll || distance > mTouchSlop) {
        ...
        if (parent != null) {
            parent.requestDisallowInterceptTouchEvent(true);
        }
        ...
    }
    ...
}

ok, thats why our interception not work anymore after the scrolling offset bigger than mTouchSlop.

So after that I checked the Google Plus app in both Android and IOS. I found one thing is different . In Android version when you scrolling the list the bottom menu will slideup or slidedown using one continuous animation but IOS with frame by frame. Means in IOS you can scrolling little by little and bottom menu will slide frame by frame. But Android version is not . So I guess Android version is not listening the scrolling offset of listview yet. Just listen listview is trying to scrolling up or down .

Then I tried to use that onInterceptTouchEvent function.


@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            mInitialX = event.getX();
            mInitialY = event.getY();
            break;
        case MotionEvent.ACTION_MOVE:
            final float x = event.getX();
            final float y = event.getY();
            final float yDiff = y - mInitialY;
            final float xDiff = x - mInitialX;
            if (mListener != null) {
                mListener.onScrollingBy(xDiff, yDiff);
            }
        break;
    }
    return super.onInterceptTouchEvent(event);
}



It also works. But I still could not solve that listen scrolling problem.

It should be easier for Google to support this listener . Look through the codes and no reason for them to not put this inside of APIs. :(

And another solution for listening scrolling up or down is checking the scrolling state and first visible item inside of listview . But still could not get the scrolling offset accurately.

Comments

Popular posts from this blog

A wired issue of MediaPlayer on Android

Problem when using Jackson json parser in Android.

Gradle issue - peer not authenticated