我在一个活动一个图形窗口和它工作正常,地图显示,并且响应水龙头,我可以很容易地提取出位置。但是,这种处理器也响应捏变焦,因此,如果用户尝试捏变焦,应用程序的响应,如果他们窃听(,这是非常令人困惑的事)。
我怎样才能到水龙头反应在图形窗口和只挑选了单一的水龙头,特别是忽视了捏变焦和双水龙头?
我需要使用的onTouchEvent(),而不是ONTAP()?如果是的话我怎么区分不同的触摸事件之间,以及如何访问的GeoPoint?
下面是从我的MapActivity内code:
类MapOverlay扩展com.google.android.maps.Overlay
{
@覆盖
公共布尔中的onTap(GeoPoint对象磷,MapView类图)
{
如果(P!= NULL)
{
//做的东西用的GeoPoint
返回true; //我们处理的自来水
}
其他
{
返回false; //我们没有处理好龙头
}
}
}
解决方案
在很多头刮,并尝试不同的方法,这一个运作良好至今。在code如下议案事件。当我们得到一个ACTION_DOWN事件,它标志着isPinch标志为假(我们不知道这是否是一个捏或还没有),但只要我们得到一个触摸事件(即ACTION_MOVE)涉及两个手指,isPinch设为如此,所以当和Ontap()事件触发,它可以查看是否有一个捏或没有。
类MapOverlay扩展com.google.android.maps.Overlay
{
私人布尔isPinch = FALSE;
@覆盖
公共布尔中的onTap(GeoPoint对象磷,图形页面地图){
如果(isPinch){
返回false;
}其他{
Log.i(TAG,TAP!);
如果(P!= NULL){
handleGeoPoint(对);
返回true; //我们处理的自来水
}其他{
返回false; //空的GeoPoint
}
}
}
@覆盖
公共布尔的onTouchEvent(MotionEvent E,图形页面图形页面)
{
int的手指= e.getPointerCount();
如果(e.getAction()== MotionEvent.ACTION_DOWN){
isPinch = FALSE; //接触下来,不知道这是否是捏又
}
如果(e.getAction()== MotionEvent.ACTION_MOVE&安培;&安培;手指== 2){
isPinch = TRUE; //两个手指,高清捏
}
返回super.onTouchEvent(即图形页面);
}
}
I have a MapView in an activity and it works fine, the map shows, and it responds to taps, and I can extract the location easily. However this handler is also responding to the pinch-zoom, so if a user tries to pinch-zoom, the app responds as if they tapped (and it's very confusing for them).
How can I respond to taps on a MapView and only pick up single-taps, specifically ignoring pinch-zoom and double-taps?
Do I need to use OnTouchEvent() instead of OnTap()? If so how do I distinguish between the different touch events, and how do I access the GeoPoint?
Here's the code from inside my MapActivity:
class MapOverlay extends com.google.android.maps.Overlay
{
@Override
public boolean onTap(GeoPoint p, MapView map)
{
if ( p!=null )
{
// Do stuff with the geopoint
return true; // We handled the tap
}
else
{
return false; // We didn't handle the tap
}
}
}
解决方案
After much head-scratching and trying various approaches, this one is working well so far. The code follows the motion events. When we get an ACTION_DOWN event, it marks the isPinch flag as false (we don't know if it's a pinch or not yet), but as soon as we get a touch event (i.e. ACTION_MOVE) involving two fingers, isPinch is set to true, and so when the onTap() event fires, it can see if there was a pinch or not.
class MapOverlay extends com.google.android.maps.Overlay
{
private boolean isPinch = false;
@Override
public boolean onTap(GeoPoint p, MapView map){
if ( isPinch ){
return false;
}else{
Log.i(TAG,"TAP!");
if ( p!=null ){
handleGeoPoint(p);
return true; // We handled the tap
}else{
return false; // Null GeoPoint
}
}
}
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView)
{
int fingers = e.getPointerCount();
if( e.getAction()==MotionEvent.ACTION_DOWN ){
isPinch=false; // Touch DOWN, don't know if it's a pinch yet
}
if( e.getAction()==MotionEvent.ACTION_MOVE && fingers==2 ){
isPinch=true; // Two fingers, def a pinch
}
return super.onTouchEvent(e,mapView);
}
}
上一篇:安卓:sqlite的储蓄字符串数组?数组、字符串、sqlite
下一篇:StateListDrawable中的ListView奇怪断色在一定条件下条件下、在一、奇怪、StateListDrawable