listView 的回弹overScrollBy


ListView有一个控制滑动到边缘的处理方法

代码:

@Override
	protected boolean overScrollBy(int deltaX,int deltaY,int scrollX, int scrollY, int scrollRangeX,int scrollRangeY, int maxOverScrollX,
			int maxOverScrollY, boolean isTouchEvent){ 
		//maxOverScrollY---Number of pixels to overscroll by in either direction along the Y axis 即:默认值为0
		return super.overScrollBy(deltaX, deltaY, scrollX, scrollY,scrollRangeX, scrollRangeY, maxOverScrollX,maxOverScrollY,isTouchEvent);  
	}


重写ListView的overScrollBy()实现 具有弹性的ListView,

代码如下:

public class MyListView extends ListView{
	private Context context;

	public MyListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		this.context = context;
	}

	public MyListView(Context context, AttributeSet attrs) {
		this(context,attrs,0);
		// TODO Auto-generated constructor stub
	}

	public MyListView(Context context) {
		this(context,null);
		// TODO Auto-generated constructor stub
	}
	private   int mMaxOverDistance = 120;
	@Override
	protected boolean overScrollBy(int deltaX,int deltaY,int scrollX, int scrollY, int scrollRangeX,int scrollRangeY, int maxOverScrollX,
			int maxOverScrollY, boolean isTouchEvent){ 
		//This is where the magic happens, we have replaced the incoming maxOverScrollY with our own custom variable mMaxYOverscrollDistance; 
		return super.overScrollBy(deltaX, deltaY, scrollX, scrollY,scrollRangeX, scrollRangeY, maxOverScrollX, mMaxOverDistance, isTouchEvent);  
	}
	


}


 
  


 
 

你可能感兴趣的:(android,代码类)