鄙人在做这个项目的时候,主界面是ListView,ListView顶部添加了ViewPager,运行时滑动ViewPager时会失去焦点,以下是处理办法,只需要对ListView重写onTouchListener方法就可以了,如下:

(注:大家只需将下面的代码复制使用就可以了)
viewPager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
PointF downP = new PointF();
PointF curP = new PointF();
int act = event.getAction();
if(act == MotionEvent.ACTION_DOWN || act == MotionEvent.ACTION_MOVE || act == MotionEvent.ACTION_UP){
((ViewGroup) v).requestDisallowInterceptTouchEvent(true);
if (downP.x == curP.x && downP.y == curP.y) {
return false;
}
}
return false;
}
});

5148

被折叠的 条评论
为什么被折叠?



