
在垂直排列的listView中嵌套水平排列的HorizontalListView会产生焦点问题,导致水平滑动不灵敏。
##灵感
ListView 添加viewPager为header时,viewPager滑动失去焦点的解决办法
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;
}
});##解决方案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 listViewPeople.setOnTouchListener(new OnTouchListener() {
public boolean (View v, MotionEvent event) {
// TODO Auto-generated method stub
PointF downP = new PointF();
PointF curP = new PointF();
int act = event.getAction();
if (act == MotionEvent.ACTION_DOWN) {
downP.y = event.getY();
downP.x = event.getX();
}
if (act == MotionEvent.ACTION_MOVE) {
curP.y = event.getY();
curP.x = event.getX();
}
if (curP.x != 0 || curP.y != 0) {
if ((Math.abs(curP.y - downP.y)) < (Math.abs(curP.x
- downP.x))) {
((HorizontalListView) v)
.requestDisallowInterceptTouchEvent(true);
}
}
return false;
}
});




近期评论