5

I've searched some time on google and on stackoverflow but i can't find a solution. Is there any posibility to get a listview overscroll on Android 2.2 or 2.1 like the sense ui does?! Like here in my alarm view: AlarmView Sense UI

Fabian
  • 2,693
  • 2
  • 21
  • 33
  • I think Overscroll is implemented in Android OS and is not configurable the user. I know CyanogenMod has this implemented though – Joe Simpson Aug 12 '11 at 15:17
  • 1
    Can you elaborate on what the sense ui does? – Ted Hopp Aug 12 '11 at 15:25
  • @Ted Hopp Of course, the sense UI overscroll is a bit iPhone like. you can pull the view down an it goes down smooth, than you release and the view slides back to top again. Here is an images from my HTC Desire from the alarm view: [AlarmView Sense UI](http://imageshack.us/photo/my-images/41/senseoverscroll.png/) Maybe there is any existing view for this? – Fabian Aug 15 '11 at 10:39
  • Unfortunately the API for overscrolling was not released until 2.3 or higher. However, it clearly is possible if you are willing to copy & modify AOSP source as necessary into your workspace. Both UberMusic and ADW EX offer overscroll for 2.1+. – Tom Aug 20 '11 at 13:06

5 Answers5

14

I'm shocked to see Chirag's answer being highly rated like this. It isn't helpful to anyone because its incomplete and doesn't build. It also doesn't cite its source.

The original code is found here: http://code.google.com/p/scroll-pager/

Also note that the scroll-pager code is released under the GPL license.

UPDATE : I talked to the author of scroll-pager and he has now switched to the MIT license.

Jozua
  • 1,274
  • 10
  • 18
1

http://developer.android.com/reference/android/widget/ScrollView.html

You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.

sky wing
  • 11
  • 2
1

I can see this post is pretty old, but I've recently released this open-source project on GitHub which solves this problem and could help others solve similar over-scroll issues in the future.

It basically provides an iOS-like over-scrolling effect for many core Android scrollable views - ListView is one of them, and is very easy to apply.

Specifically for list-views, all you have to do to enable it this:

ListView listView = ... // For example: (ListView) findViewById(R.id.list_view);
OverScrollDecoratorHelper.setUpOverScroll(listView);

And to include the project in yours, add this to your build.gradle:

dependencies {
    // ...

    compile 'me.everything:overscroll-decor-android:1.0.0'
}
d4vidi
  • 2,407
  • 26
  • 27
1

Listview has built-in support for overscrolling. Check out setOverscrollMode and related methods setOverscrollHeader and setOverscrollFooter. ListView makes use of the overscroll header/footer by overriding AbsListView.onOverscrolled; if you want different behavior, you can implement it by overriding it yourself.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
-5

Define scrollview in your xml file.

Then in your java file wite this:

scrollView = (ScrollView) findViewById(R.id.scr);
    contentView = (ViewGroup) findViewById(R.id.r2);
    scrollView.setOnTouchListener(new ScrollPager(scrollView, contentView));
    scrollView.post(new Runnable() {
        public void run() {
            scrollView.scrollTo(0, contentView.getPaddingTop());
        }
    });

And Add a class in above java file:

public class ScrollPager implements OnTouchListener
public ScrollPager(ScrollView aScrollView, ViewGroup aContentView)
    {
        mScrollView = aScrollView;
        mContentView = aContentView;
        scroller = new Scroller(mScrollView.getContext(), new OvershootInterpolator());
        task = new Runnable()
        {
            public void run()
            {
                scroller.computeScrollOffset();
                mScrollView.scrollTo(0, scroller.getCurrY());

                if (!scroller.isFinished())
                {
                    mScrollView.post(this);
                }
            }
        };
    }
Chirag Shah
  • 2,058
  • 2
  • 20
  • 30