有没有办法在滚动ViewPager中的项目时锁定ListView的垂直滚动?或者改变ViewPager的水平滚动灵敏度?
谢谢。
最后编辑
这是我的更新解决方案。感谢Masoud Dadashi的回复,您的评论最终让我想出了解决我的问题的方法。
这是我的自定义ListView类:
public class FolderListView extends ListView {
private float xDistance, yDistance, lastX, lastY;
// If built programmatically
public FolderListView(Context context) {
super(context);
// init();
}
// This example uses this method since being built from XML
public FolderListView(Context context, AttributeSet attrs) {
super(context, attrs);
// init();
}
// Build from XML layout
public FolderListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// init();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if (xDistance > yDistance)
return false;
}
return super.onInterceptTouchEvent(ev);
}
}