Question

Is there a way to set up the gallery view so that only one image is in view at a time? I have created a gallery view with thumbnails of images. As the user clicks on an image, I want to start a new activity which displays the actual selected image in a new gallery view. Now when the user swipes his finger, he can then see the subsequent image. Is there a way to achieve this?

Was it helpful?

Solution 3

Got an alternative solution figured out while searching on the web. The simpler solution is to subclass the Gallery class and just set onFling to always return false. Here is the reference to the solution:

How can I limit fling in Android gallery to just one item per fling?

Here is my combined implementation based on inputs from users "Someone Somewhere" and "vmihalca" as listed in the above link:

public class SlowGallery extends Gallery {

    public SlowGallery(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public SlowGallery(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SlowGallery(Context context) {
        super(context);
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
         return false;
    }

}

OTHER TIPS

You can use "custom Adapter" for your gallery view with an image view and use "match_parent" or "fill_parent" for "LayoutParams" of image view in custom Adapter in getView(int position, View convertView, ViewGroup parent) method.

public View getView(int position, View convertView, ViewGroup parent) {

    imageView.setLayoutParams(...);


    return imageView;
}   

references:
developer.android
developer.android
developer.android

I had the same problem and I did a little hack that worked.In my case the images were static so I numbered the images 0-100 using bulk rename.The did the same with the corresponding thumbnails.I created two activities one with a gridview(You can use a galleryview) to hold the thumbs and another with a galleryview I set the onclicklistener for the gridview to get the id of the clicked thumb and pass it to the activity with the galleryview as an intent extra.The galleryview the grabs the id and jumps to the image with the given id.Check this

answer and thistutorial

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top