7

I want to do something when the user has scrolled >90% down, so I thought I could just add a onScrollListener like I would in a ListView. Unfortunatly, ScrollView doesn't seem to have a similar method. Is there any way I can do what I want; getting a notification when the user scrolls approx 90% down?

Thanks, Erik

Erik
  • 5,681
  • 8
  • 31
  • 32

4 Answers4

12

This is what I end up doing to know if the user was interacting with my ScrollView or not:

findViewById(R.id.scrollview).setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL:
        case MotionEvent.ACTION_MOVE:
            setScrollState(OnScrollListener.SCROLL_STATE_FLING);
            break;
        case MotionEvent.ACTION_DOWN:
            setScrollState(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            setScrollState(OnScrollListener.SCROLL_STATE_IDLE);
            break;
        }
        return false;
    }
});
mmathieum
  • 506
  • 5
  • 14
6

You can try extending ScrollView and overriding View#onScrollChanged and the doing your checks there. You have to extend ScrollView since onScrollChanged is a protected method.

Rich Schuler
  • 41,814
  • 6
  • 72
  • 59
  • New problem: How do I get the 'height' of the full content that scrolls? I have the current position now, but I want to tell how 'far' the scrollbar is. getHeight() doesn't return correct values, probably the height on screen and not of the content. – Erik Aug 19 '10 at 15:32
  • 1
    Use getHeight on the child view that you put into the ScrollView. ScrollView works basically by telling the child view be as large as it wants and then acts as a viewport to it. – Rich Schuler Aug 19 '10 at 17:21
0

You can implement an onTouchListener and use the getScrollX and getScrollY callbacks of the view

Frederick Nyawaya
  • 2,285
  • 1
  • 15
  • 19
-1

If you want a scrolling view that works like a listview, may I suggest trying out a horizontal listView library:

https://github.com/sephiroth74/HorizontalVariableListView

it's based on the original ListView, and it works very well.

it has its OnScrollListener , and even though the website says it supports Android 2.3 and above, I think it should work from API 7 and above (and with some tweaks even older).

android developer
  • 114,585
  • 152
  • 739
  • 1,270