我有一個活動,實現了一個手勢檢測器來捕捉用戶導航到其他屏幕的輸入。這工作正常 - 但 - 我最近更新了一個派生自BaseActivity的類來添加一個onClick函數,現在這個click事件似乎阻止了onFling被擊中。 onClick綁定到我的屏幕上的TextView區域(在LinearLayout中)。 resultsClick方法使用XML佈局中的onClick屬性連線到TextView。Android onClick攔截onFling
我試過改變onSingleTapUp和onDown返回值沒有運氣。我也嘗試將日誌語句添加到下面的所有函數中。當我在TextView區域中投擲時,它們都沒有閃光,但是它們在屏幕的其他區域進行。
也許我使用了錯誤的搜索條件,但似乎找不到解決此問題的示例 - 但我確信此問題已在之前解決。
public class DerivedActivity extends BaseActivity
{
...
/**
* resultsClick - The user clicked on the Results area
* @param v
*/
public void resultsClick(View v)
{
try
{
Log.i(this.toString(), "resultsClick");
startActivity(new Intent(this, Results_TabHost.class));
}
catch (Exception e)
{
Log.e(this.toString(), "Exception" + e.toString());
}
}// end resultsClick
...
}
這是基礎類,它實現GestureListener代碼
public class BaseActivity extends ActivityGroup
implements OnGestureListener
{
...
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
public boolean onFling(MotionEvent e1,
MotionEvent e2,
float velocityX,
float velocityY)
{
try
{
Log.i(this.toString(), "onFling");
// jump right out if not a swipe/fling
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
{
return false;
}
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE &&
Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
Log.i(this.toString(), "fling left");
rightArrowClick(null);
}
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE &&
Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
Log.i(this.toString(), "fling right");
leftArrowClick(null);
}
}
catch (Exception e)
{
Log.e(this.toString(), "Exception" + e.toString());
}
return true;
}// end onFling
// These next methods we are required to have - even if unused -
// in order for the Gesture Handling to work
@Override
public boolean onTouchEvent(MotionEvent motionEvent)
{
return this.gestureDetector.onTouchEvent(motionEvent);
}
@Override
public void onLongPress(MotionEvent e)
{
// Intentionally not handling - must be overridden by listener class
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
// Intentionally not handling - must be overridden by listener class
// Intentionally returning true - per code examples
return true;
}
@Override
public void onShowPress(MotionEvent e)
{
// Intentionally not handling - must be overridden by listener class
}
@Override
public boolean onSingleTapUp(MotionEvent e)
{
// Intentionally not handling - must be overridden by listener class
// Intentionally returning true - per code examples
return true;
}
@Override
public boolean onDown(MotionEvent e)
{
// Intentionally not handling - must be overridden by listener class
// Intentionally returning true - per code examples
return true;
}
...
}
@CodeFusionMbile - 謝謝你的建議。我只是嘗試使用上面的代碼更新onTouchEvent,但它在我看到的行爲中沒有任何區別。我爲每個手勢事件添加了一個日誌來確保。當我嘗試在屏幕上滑動時,我看到結果中的日誌單擊,但我沒有看到其他任何人正在登錄。 – bursk 2010-11-22 21:19:12