1
我在android開發人員組中提出了一個類似的問題,但還沒有收到回覆,所以我想我會在這裏嘗試我的運氣。在圖庫中實現垂直滑動的問題
我想實現一個畫廊上的垂直滑動,我讓它工作......有點。我將Gallery分類,以便我可以覆蓋onFling和onDown方法。
這裏是我用來重寫這些方法的代碼:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
if (m_curTouchPos == NO_CURRENT_TOUCH_POS || m_callback == null)
return super.onFling(e1, e2, velocityX, velocityY);
float e1x = e1.getX();
float e1y = e1.getY();
float e2x = e2.getX();
float e2y = e2.getY();
float offPath = Math.abs(e1x - e2x);
float distance = Math.abs(e1y - e2y);
if (offPath < s_swipeMaxOffPath &&
//Math.abs(velocityY) >= s_swipeMinVelocity &&
distance >= s_swipeMinDistance)
{
if (e1y > e2y)
{
m_callback.onSwipeUp(m_curTouchPos);
//return true;
}
else if (e2y > e1y)
{
//TODO: IMPLEMENT THIS
//m_callback.onSwipeDown(m_curTouchPos);
//return true;
}
}
m_curTouchPos = NO_CURRENT_TOUCH_POS;
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public boolean onDown(MotionEvent eve)
{
m_curTouchPos = pointToPosition((int)eve.getX(), (int)eve.getY());
return super.onDown(eve);
}
的問題是,當我做一個垂直的掠過onFling不會被調用......爲了進入onFling方法我必須按下畫廊中的項目,慢慢向左或向右滑動,然後垂直滑動。
水平滑動總是進入onFling方法。
關於如何使這項工作的任何想法?