Search code examples
androidimageviewzoominghorizontal-scrollingpinch

Pinch to Zoom ImageView inside a HorizontalPager (RealViewSwitcher) android


There is "double tap to zoom" / "pinch to zoom" ImageView (ImageViewTouch) from here.
And there is "Horizontal Pager" by Yoni Samlan here.

Please help me how to embed pinch-zoom imageview (ImageViewTouch) inside "HorizontalPager". I am facing difficulty in this as both classes uses onTouchEvent().

Note: Multiple ImageViewTouch objects inside HorizontalPager object (which is expected to allow pinch-zooming and sliding to another image (ImageViewTouch)


Solution

  • It's done, this way... HorizontalPager will trap the onTouchEvent() first. It will pass the event to child view which is ImageViewTouch. If it handled the event (determined by boolean value returned by onTouchEvent()), It will also simply return from onTouchEvent() as handled. If child view (ImageViewTouch) did not handle event, it will handle this event by taking necessary action related to the event and return as handled.

    Of course I have done some modifications to HorizontalPager and ImageViewTouch classes to co-ordinate this.