开发者

which event is used to slide finger left and right ward in android?

i am creating image gallery if i click on grid view of images it shows 开发者_如何学编程full screen image.

now i want to implement functionality of touch screen or finger sliding left and right ward to change images.

any one guide me which event should i use or whats the procedure

any help would be appriciated.


using this example we can detect gestures of moving finger left , right , up and downward

http://android-journey.blogspot.com/2010/01/android-gestures.html


You have to implement onTouchEvent and determine when the slide is actually happening. There is no built-in event for it.


I implemented this behavior in my application JustPictures, for the exact same purpose. I did it via onTouchEvent(MotionEvent event) :

if(event.getAction()==MotionEvent.ACTION_MOVE){...}

You can get the X position of the finger with event.getX(), and compute the offset from the last time you received the event. You can then update an offset variable that is private to your view, and postInvalidate(). Then your onDraw method takes care of translating the canvas by the current offset.


I've used onGesturePerformed callback, but you have to record the gesture pattern using the Emulator, save the pattern on the res and do something like this: Activity:

mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mLibrary.load()) {
 finish();
}           
GestureOverlayView gestures = (GestureOverlayView)   
findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this);

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
  ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
  if (predictions.size() > 0 && predictions.get(0).score > 1.0) { ... }}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜