Search code examples
javaandroidandroid-imageviewswipeontouchlistener

Android - Image zoom library


I have this kind of use-case

User is looking at ImageView, this ImageView should implement two types of gestures:

  • Swipe left/right to move to previous/next image
  • Zoom image (two-fingers, double-tap)

For swipe I've used implementation from here https://stackoverflow.com/a/8806468/492624
You can see it here: https://github.com/smarek/Simple-Dilbert/blob/master/src/com/mareksebera/dilbert/ActivitySwipeDetector.java

For double-tap, two-fingers I've used library named PhotoView
You can see it here: https://github.com/smarek/Simple-Dilbert/blob/master/src/com/mareksebera/dilbert/ImageZoomActivity.java

The problem is, I'm not currently able to combine these two implementations.
I'd like user to have both options on one page, one idea is to rewrite it from "single ImageView" to "ViewPager", to implement paging on lower level (not as OnTouchListener) and use PhotoView as library to provide zoom function.

Possible user-scenario is for me:

  • If image is not zoomed, user can use swipe gestures to move through images
  • If image is zoomed, user can work with zoom and move in zoomed image, but left-right swipe will not work in this case, so user will be forced to un-zoom it to be able to display another

So two qeustions are on the table

  1. Whether my user-scenario is right and understandable
  2. If there is option to combine these or use another library without need to rewrite it to ViewPager

Solution

  • Can't you just use the code from sample of PhotoView?

    This works well for me: https://play.google.com/store/apps/details?id=uk.co.senab.photoview.sample