Search code examples
androidimageviewphoto-gallery

What's the best way on Android to create a photo gallery (fullscreen)


I wonder what's the best way to create a photo gallery for my app. I get the pictures from an RSS feed and I want to display each of them in fullscreen. What should I use ? I tried with an ImageView but the images are resized in a bad way (they don't keep the original dimensions)

I used this answer to implement my gallery : Android Gallery fullscreen

Thank's

EDIT :

Here's the XML layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
        android:id="@+id/galleryPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

    </android.support.v4.view.ViewPager>

</LinearLayout>

And here's the code I use in my adapter to load the images :

@Override
public Object instantiateItem(View collection, int position) {
    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    ImageDownloader.getInstance().download(gallery.get(position), ImageFormat.CONTENT_316, imageView);

        ((ViewPager) collection).addView(imageView, 0);

        return imageView;
}

Solution

  • The code I used above was almost right, I just changed ImageView.ScaleType.FIT_XY to ImageView.ScaleType.CENTER_CROP

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <android.support.v4.view.ViewPager
            android:id="@+id/galleryPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
        </android.support.v4.view.ViewPager>
    
    </LinearLayout>
    

    And here's the code I use in my adapter to load the images :

    @Override
    public Object instantiateItem(View collection, int position) {
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        imageView.setScaleType(**ImageView.ScaleType.CENTER_CROP**);
        ImageDownloader.getInstance().download(gallery.get(position), ImageFormat.CONTENT_316, imageView);
    
            ((ViewPager) collection).addView(imageView, 0);
    
            return imageView;
    }