2

I have a fragment which contains a ListView and multiple images (7-10) are displaced each time fragment is launched.

I tried using different libraries for the zooming purpose but the ListView won't show up as then I will have to replace ImageView with library's defined ImageView

How can I add zoom in/out for those images?

EDIT: I want to add zoom in/out to the ListView that contain different number of images on each load, as my question states.

EDIT 2: This is getview method of my Custom Adapter. How do I attach PhotoViewAttacher in it?

public View getView(int position, View convertView, ViewGroup parent) {
    View iv = convertView;
    ViewHolder holder = null;

    if (iv == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        iv = inflater.inflate(layoutResourceId, parent, false);
        holder = new ViewHolder();

        holder.image = (ImageView) iv.findViewById(R.id.imagview);
        iv.setTag(holder);
    } else {
        holder = (ViewHolder) iv.getTag();
    }

    Picasso.with(context)
            .load((Integer) data.get(position))
            .resize(999, 720)
            .onlyScaleDown()
            .centerInside()
            .into(holder.image);

    return iv;
}

static class ViewHolder {
    ImageView image;
    PhotoViewAttacher mAttacher;
}

}

Atiq
  • 14,435
  • 6
  • 54
  • 69
  • Possible duplicate of [How to implement zoom effect for image view in android?](http://stackoverflow.com/questions/8399296/how-to-implement-zoom-effect-for-image-view-in-android) – Rami Jan 17 '16 at 09:00
  • @Rami I have written that my Images are in `ListView` and if if i use a lib ( as described in the answer to that question) for zooming it wont load the `ListView`, the libs i cam across are for single `ImageViews`. – Atiq Jan 17 '16 at 09:03
  • can you add the code with the zoom method you implemented so we can try and figure out whats wrong? – Daniel Netzer Jan 17 '16 at 09:11
  • @Anders Sure they are for single ImageView, you can use them in your getView() method of the adapter and apply the animation to your list item ImageView. – Rami Jan 17 '16 at 09:15
  • I tried one `ImageViewTouch` through my custom Adapter but my list wont show after adding it as i would have to use that lib's own imageview. so i thought it wont work that way, lemme try again with lib that is described in that question and then i will update my question okay – Atiq Jan 17 '16 at 09:25
  • @Rami where i can find the jar file of [this library](https://github.com/chrisbanes/PhotoView/tree/master/library/src/main)? thanks for ur time – Atiq Jan 17 '16 at 09:29
  • @Anders I don't think there is a .jar file, you need to integrate it with Gradle. – Rami Jan 17 '16 at 09:35
  • Second Answer in [this](http://stackoverflow.com/questions/21749374/picasso-and-photoview-library-loads-image-into-imageview-weird) question worked perfect for me – Atiq Jan 17 '16 at 12:06
  • @Rami I am using PhotoView with Picasso and some images appears smaller on listview? and first time some images are not loaded when i scroll, when i scroll back upward they start appearing? – Atiq Jan 18 '16 at 07:19
  • 1) They appears smaller, maybe because they have a smaller size. Try to open the image url in browser and check that. -- 2) Because the lib download images in AsyncTasks (asynchronous). – Rami Jan 18 '16 at 07:23
  • Actually am loading them from resources, with picasso alone they appear fine but when i use photoview then sometime there is gap between images and also some of the images are small – Atiq Jan 18 '16 at 07:27

2 Answers2

1

This is how I made it work

After importing PhotoView

In layout file (if you use layout):

<uk.co.senab.photoview.PhotoView
    android:id="@+id/your_photo_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ... />

And in adapter

PhotoView photoView = (PhotoView) findViewById(R.id.your_photo_view);

Picasso.with(context)
    .load(file)
    ...
    .into(photoView); 

Thanks everyone for your time.

Atiq
  • 14,435
  • 6
  • 54
  • 69
0

Instead of taking simple ImageView in BaseAdapter's getView list item add TouchImageView

pRaNaY
  • 24,642
  • 24
  • 96
  • 146