PullToRefreshListView嵌套listview产生的冲突,导致listview滑动缓慢
public class MyViewPager extends ViewPager{
private float mDownX;
private float mDownY;
public MyViewPager(Context context)
{
this(context, null);
}
public MyViewPager(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
//DOWN 事件的时候记录下当前的xy左标
mDownX=ev.getX();
mDownY=ev.getY();
getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_MOVE:
/*MOVE 事件后计算x轴y轴的移动距离 ,如果x轴移动距离大于y轴,
那么该事件有ViewPager处理,否则交给父容器处理*/
if(Math.abs(ev.getX()-mDownX)>Math.abs(ev.getY()-mDownY)){
getParent().requestDisallowInterceptTouchEvent(true);
}else{
getParent().requestDisallowInterceptTouchEvent(false);
}
break;
case MotionEvent.ACTION_CANCEL:
getParent().requestDisallowInterceptTouchEvent(false);
break;
default:
break;
}
return super.dispatchTouchEvent(ev);
}
@Override
protected void onMeasure(int arg0, int arg1) {
int expandSpec = MeasureSpec.makeMeasureSpec(400, MeasureSpec.AT_MOST);
super.onMeasure(arg0, expandSpec);
}