Tôi đã làm lại một giải pháp và cuối cùng tìm ra một cách rất đơn giản để thực hiện nó theo cùng một cách nó được thực hiện trên Gmail: các HorizontalScrollView sẽ di chuyển cho đến khi nó đạt đến một các cạnh của nó. Sau đó, trên cuộn tiếp theo, toàn bộ trang sẽ cuộn.
Tất cả những gì cần thiết là ghi đè HorizontalScrollView để kiểm tra hướng cuộn so với cạnh và cũng đảm bảo nội dung thực sự có thể cuộn.
@Override
public boolean onTouchEvent(MotionEvent ev)
{
if (no_scrolling)
return false;
// Standard behavior
//
return super.onTouchEvent(ev);
}
boolean no_scrolling = false;
float old_x, old_y;
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
int action = ev.getActionMasked();
Log.d(at_data.TAG, "HSV scroll intercept: " + String.format("0x%08x", action));
if (action == MotionEvent.ACTION_DOWN)
{
old_x = ev.getX();
old_y = ev.getY();
no_scrolling = false;
}
else if (action == MotionEvent.ACTION_MOVE)
{
float dx = ev.getX() - old_x;
float dy = ev.getY() - old_y;
if (Math.abs(dx) > Math.abs(dy) && dx != 0)
{
View hsvChild = getChildAt(0);
int childW = hsvChild.getWidth();
int W = getWidth();
Log.d(at_data.TAG, "HSV " + childW + " > " + W + " ? dx = " + dx + " dy = " + dy);
if (childW > W)
{
int scrollx = getScrollX();
if ((dx < 0 && scrollx + W >= childW) || (dx > 0 && scrollx <= 0))
{
Log.d(at_data.TAG, "HSV Wider: on edge already");
no_scrolling = true;
return false;
}
else
{
Log.d(at_data.TAG, "HSV Wider: can scroll");
no_scrolling = false;
}
}
else
{
Log.d(at_data.TAG, "HSV cannot scroll in desired direction");
no_scrolling = true;
}
}
}
// Standard behavior
//
return super.onInterceptTouchEvent(ev);
}
xem [this] (http://stackoverflow.com/questions/7774642/scroll-webview-horizontally-inside-a-viewpager) trả lời. Nhưng thay vì WebView tùy chỉnh trong câu trả lời đó, bạn có thể cần mở rộng HorizontalScrollingView của mình. – grine4ka