类似iPhone的弹性ListView滚动
从2.3开始,android开始支持listview的overscroll, 应该很方便可以做出类似iPhone的弹性滚动,及越过list顶端或者底端,然后弹性滚回。昨天google了半天的例子,一个没找到,今天又试了试,发现用很简单的方式就可以实现这个效果。大致如下:
继承ListView
private int delY;
private boolean action_up;
在 onTouchEvent(){
...
case MotionEvent.ACTION_MOVE:
delY = (int) (preY - y);
preY = y;
break;
case MotionEvent.ACTION_UP:
action_up = true;
break;
}
然后在2.3新增的onOverScrolled方法中做如下实现
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { this.scrollBy(0, delY / 2); if (action_up) { this.scrollTo(0, 0); }}