我有一个地图视图,其上面有叠加项目。叠加项目在录制时会有一个动作。 问题是当我使用捏缩放时如果我的手指恰好位于物品的某个位置,当我抬起它时,onTap()被调用。我怎么能阻止这个?
谢谢, 杰森
答案 0 :(得分:4)
为overlayItem实现motioneventListener而不是当前的eventListener并检查指针计数
@Override
public boolean onTouchEvent(final MotionEvent event)
{
if(event.getPointerCount() == 1)
{
// do onTap stuff
}
}
答案 1 :(得分:0)
这是我最终得到的解决方案如果对任何人有任何帮助:
private static Method GetPointCountMethod;
private boolean mIsTouchMove = false;
private static boolean mTapable = true;
static {
// Check if the getPointerCount method is availabe (aka api level 5)
try {
GetPointCountMethod = MotionEvent.class.getMethod("getPointerCount");
/* success, this is a newer device */
}
catch (NoSuchMethodException nsme) {
/* failure, must be older device */
}
};
// Invoke the getPointCount Method if it exists
private int getPointCount(MotionEvent event)
{
try {
return (Integer) GetPointCountMethod.invoke(event);
}
catch (IllegalArgumentException e) {
e.printStackTrace();
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
return -1;
}
@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
// Set the tappable to be only when the map is realy just tapped and not moved or zoomed
if (event.getAction() == MotionEvent.ACTION_UP) {
if (GetPointCountMethod != null) {
if (getPointCount(event) == 1) {
if (mIsTouchMove) {
mIsTouchMove = false;
}
else {
mTapable = true;
// Finaly - a Tap! :
}
}
}
}
else if (event.getAction() == MotionEvent.ACTION_MOVE) {
mTapable = (false);
mIsTouchMove = true;
}
// let the rest do their job
return super.dispatchTouchEvent(event);
}
仍然没有1.6的支持,这就是为什么这仍然是开放的等待,看看是否有办法在1.6中做到这一点