我有一个使用 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;
}
}