Monday, April 7, 2014

onLongPress gesture does not recognize


public class GameView extends SurfaceView implements SurfaceHolder.Callback,
OnGestureListener, OnTouchListener {
private GestureDetector myGD ;/ / gesture recognition
private static final int FLING_MIN_VELOCITY = 0 ;/ / slowest moving speed
private float FLING_MIN_DISTANCE = 50 ;/ / shortest path
touch......
public GameView (GameActivity father) {
......

this.setClickable (true);
this.setLongClickable (true);
this.setOnTouchListener (this);
myGD = new GestureDetector (this);
myGD.setIsLongpressEnabled (true);
}

@ Override
public boolean onTouch (View v, MotionEvent event) {
/ / TODO Auto-generated method stub
return myGD.onTouchEvent (event);
}
@ Override
public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
/ / TODO Auto-generated method stub
/ / Left slide
if ((e1.getX () - e2.getX ())> FLING_MIN_DISTANCE
&& Math.abs (velocityX)> FLING_MIN_VELOCITY) {
Log.i ("gesture", "onFling-Left");

}
/ / Slide
else if (e2.getX () - e1.getX ()> FLING_MIN_DISTANCE
&& Math.abs (velocityX)> FLING_MIN_VELOCITY) {
Log.i ("gesture", "onFling-Right");
}
/ / Slide down
else if (e2.getY () - e1.getY ()> this.FLING_MIN_DISTANCE
&& Math.abs (velocityY)> FLING_MIN_VELOCITY) {
Log.i ("gesture", "onFling-DOWN");
}
return false;
}
@ Override
public boolean onSingleTapUp (MotionEvent e) {
/ / TODO Auto-generated method stub
Log.i ("gesture", "onSingleTapUp");
return false;
}

@ Override
public boolean onDown (MotionEvent event) {
/ / TODO Auto-generated method stub
Log.i ("gesture", "onDown");
return false;
}

@ Override
public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
/ / TODO Auto-generated method stub
Log.i ("gesture", "onScroll");
return false;
}

@ Override
public void onShowPress (MotionEvent e) {
/ / TODO Auto-generated method stub
Log.i ("gesture", "onShowPress");
}

@ Override
public void onLongPress (MotionEvent event) {
/ / TODO Auto-generated method stub
Log.i ("gesture", "onLongPress");

}
}
Code above, no matter how pressing the Executive onSingleTapUp are executed first onDown (), raised his hand after (), or onDown () -> onScroll (), or onDown () -> onScroll () -> onFling ( ) *. Not execute onShowPress () or onLongPress ().
How can we make the difference and perform onSingleTapUp (), onFling (), onLongPress () These three gestures it?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Great God you take a bubble ah take a bubble
Reply:
Rewriting systems approach onTouchEvent, the return value is true in vivo rewrite
Reply:
Check your view is used to initialize properly
Reply:
reference to the third floor ckkyjtqlt reply:
Check your view is used to initialize properly

I ask this with normal initialization view of what links?

No comments:

Post a Comment