Fr4nz
Fr4nz

Reputation: 1636

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;
}

Upvotes: 0

Views: 1707

Answers (4)

Fr4nz
Fr4nz

Reputation: 1636

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;
}

Upvotes: 0

sunil
sunil

Reputation: 6614

one way would be

  • get the image url's from the rss feed
  • show them as thumbnails in a custom gallery (can setup via horizontal linearlayout with a imageview in it, inside a scrollview)
  • use lazyloading of images to show these thumbnails
  • override onClickListener to get the click events
  • and in this onClick load the current image URL in a webview.
  • webview has good features of zoom, move along picture etc..

Upvotes: 0

Soumyadip Das
Soumyadip Das

Reputation: 1791

Use an Adapter & ListView to display images slide.

Now in the adapter item's layout use ImageView with fill_parent for both width & hight as like following code:

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY" />

you may suggest the user to use the phone in landscape mode for better performance. so keep additional layout in layout-land folder

Upvotes: 1

FoamyGuy
FoamyGuy

Reputation: 46856

I would use a ViewPager with ImageViews inside of it.

You are able to specify to the ImageView how you'd like the images to be (or not to be) streched with the android:scaleType attribute in your xml. If you share some of the code that you were using with ImageViews and maybe give a little bit more info about how you wan them to appear I can try to help you get it set up properly.

Also I suggest you take a look at Displaying Bitmaps Efficiently for best practices to use when dealing with images so as to keep the performance of your app top notch.

Upvotes: 1

Related Questions