有没有办法在滚动一个 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);
}
}