最後我一個定製尋呼機和overrided方法canScroll喜歡這樣
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (v instanceof HorizontalScrollView) {
HorizontalScrollView scroll = (HorizontalScrollView) v;
int vScrollX = scroll.getScrollX();
TableLayout table = (TableLayout) scroll.getChildAt(scroll
.getChildCount() - 1);
int diff = (table.getRight() - (scroll.getWidth()
+ scroll.getScrollX() + table.getLeft()));
if (vScrollX == 0 && diff <= 0) {// table without scroll
if (dx > 20 && this.getCurrentItem() > 0) {
this.setCurrentItem(this.getCurrentItem() - 1, true);
} else if (dx < -20
&& this.getCurrentItem() + 1 < this.getChildCount()) {
this.setCurrentItem(this.getCurrentItem() + 1, true);
}
return false; // change page
}
if (vScrollX == 0 && dx > 20) {// left edge, swiping right
if (this.getCurrentItem() > 0) {
this.setCurrentItem(this.getCurrentItem() - 1, true);
}
return false; // change page
}
if (vScrollX == 0 && dx < -20) {// left edge, swiping left
return true;// scroll
}
if (diff <= 0 && dx > 20) {// right edge, swiping right
return true;// scroll
}
if (diff <= 0 && dx < -20) {// right edge, swiping left
if (this.getCurrentItem() + 1 < this.getChildCount()) {
this.setCurrentItem(this.getCurrentItem() + 1, true);
}
return false;// change page
}
}
return super.canScroll(v, checkV, dx, x, y);
}
這可能是棘手的。將需要編寫自定義觸摸偵聽器並使用requestDisallowInterceptTouchEvent指令。看看它是如何在PhotoView庫中完成的(它可以使用ViewPager進行滾動)https://github.com/chrisbanes/PhotoView – httpdispatch 2014-10-07 11:41:27