Android ViewPager with scalable ImageView

I have a ViewPager created by ImageViews implemented as follows:

@Override public Object instantiateItem(View collection, int position) { ImageView iv = new ImageView(ctx); if (pageList.size() > position) iv.setImageBitmap(pageList.get(position)); else iv.setImageResource(R.drawable.loading); iv.setOnTouchListener(this); ((ViewPager) collection).addView(iv, 0); System.out.println("POS: " + position); return iv; } 

Is it likely that ImageView can be scaled by double-clicking (and swiping the image on the screen) or zooming?

+8
android android-viewpager image-zoom
source share
3 answers

Perhaps this is how I did it.

A FrameLayout top-level layout element that allows multiple views to stack on top of each other. FrameLayout has two children: ViewPager and ImageView , which I will use to display a larger image.

ImageView is usually hidden. I listen to touch events on images inside the ViewPager and based on these, show and hide and pan the ImageView. It works quite well. If necessary, I can provide more detailed information.

+6
source share

I used the TouchImageView class by Mike Ortiz. This is not perfect. But it's cool, because you can drop it very easily! Double-touch animation can be funny. An increase in the pinch can be caused by double taps, which are strange.

This really works well if you put it directly in the ViewPager (via the adapter class). When zoomed in, you can freely move left and right without causing the page to change unless you are right on the edge, which is really cool!

https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/ortiz/touch/TouchImageView.java

+2
source share
0
source share

All Articles