0

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;
}
Community
  • 1
  • 1
Fr4nz
  • 1,616
  • 6
  • 24
  • 33

4 Answers4

1

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.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • Thank's for your answer, I posted my code. With this code the images lose their proportions* – Fr4nz Jul 13 '12 at 14:36
1

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

Soumyadip Das
  • 1,781
  • 3
  • 16
  • 34
0

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..
sunil
  • 6,444
  • 1
  • 32
  • 44
0

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;
}
Fr4nz
  • 1,616
  • 6
  • 24
  • 33