GestureDetector を使用するアプリケーションがあり、いくつかの画像 onDown と onFling (別名 onUp) を置き換えています。ただし、場合によっては onFling が呼び出されず、結果がきれいではありません:)
このような問題に直面したことがありますか? (タイムアウトを使用する以外に) 修正/回避策を見つけましたか?
ここに小さなコードがあります:
final GestureDetector gdt1 = new GestureDetector(getApplicationContext(), new MyGestureDetector(mGestDetector, R.id.weatherFrame1));
FrameLayout weatherFrame1 = (FrameLayout)findViewById(R.id.weatherFrame1);
if (weatherFrame1 != null)
{
weatherFrame1.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(final View view, final MotionEvent event)
{
gdt1.onTouchEvent(event);
return true;
}
});
}
そして、ここに MyGestureDetector.java の一部があります
public class MyGestureDetector implements GestureDetector.OnGestureListener{
{
...
@Override
public boolean onDown(MotionEvent e)
{
int index = e.getActionIndex();
int pointerId = e.getPointerId(index);
if (startingPointerId == -1)
{
Log.i("MyGestureDetector", "Pointer is " + pointerId);
if (pointerId == 0)
{
startingPosX = e.getX(pointerId);
startingPosY = e.getY(pointerId);
startingPointerId = pointerId;
if (null != mGestureListener)
{
mGestureListener.onDown(mGestureOrigin);
}
}
}
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
startingPointerId = -1;
if (null != mGestureListener)
{
mGestureListener.onUp(mGestureOrigin);
}
return true;
}
}