I have four images in the Gallery View. When we do swipe from left to right or right to left the Gallery View moves all the images i.e if I swipe from left to right from the first image then it will move to all the four images. What I want is that when I swipe it should only move to the next image. Can someone let me know how is this possible in galleryview?
Asked
Active
Viewed 3,341 times
2 Answers
1
I think you have to work with gesture for change the images with finger swipe.For that below code may helpful for u.
import java.util.ArrayList; import android.app.Activity; import android.gesture.Gesture; import android.gesture.GestureLibraries; import android.gesture.GestureLibrary; import android.gesture.GestureOverlayView; import android.gesture.Prediction; import android.gesture.GestureOverlayView.OnGesturePerformedListener; import android.os.Bundle; import android.widget.Toast;public class GesturesActivity extends Activity implements OnGesturePerformedListener { private GestureLibrary mLibrary;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mLibrary = GestureLibraries.fromRawResource(this, R.raw.spells); 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); // We want at least one prediction if (predictions.size() > 0) { Prediction prediction = predictions.get(0); // We want at least some confidence in the result if (prediction.score > 1.0) { // Show the spell Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show(); } } }
}
enter code here

ManjotSingh
- 713
- 7
- 20
0
You can consider using a ViewFlipper with Gestures on it, look at this example:
http://www.inter-fuser.com/2009/07/android-transistions-slide-in-and-slide.html
EDIT:
Oh, obviously you should implement the gesture detection, take at look at this question/answer
-
-
it's easier to use this approach imo, overriding the standard gallery behaviour could be tedious – BFil May 18 '11 at 11:53
-
i added back and next button in this activity if i press the left button and right corresponding image i need to show.i can get image name how to pass that in gallery adapter – bamini May 19 '11 at 06:06
-
are you using the gallery or the viewflipper? first case: just do -> pos = gallery.getSelectedItemPosition(); gallery.setSelection(pos+1); - second case -> viewFlipper.showNext(); – BFil May 19 '11 at 07:15