有沒有辦法在滾動ViewPager的項目時鎖定ListView的垂直滾動?或者也許改變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);
}
}
看看這個帖子http://stackoverflow.com/questions/7900860/viewpager-in -a-listview-how-to-lock-the-rolling-axis –
謝謝,我會研究一下。 –