I've implemented zoom and pan/drag functionality in my custom relative layout successfully with the help of following links.
1). An excellent tutorial - making-sense-of-multitouch
2). (SO link) Extending RelativeLayout, and overriding dispatchDraw() to create a zoomable ViewGroup
3). (SO link) Scroll/Panning or drag in custom layout
Here's my full working code.
https://gist.github.com/pandeyGitHub/6805840 .
and my layout.xml looks like this:-
<com.myzoomproject.views.ZoomableRelativeLayout
android:id="@+id/root_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.myzoomproject.views.CustomViewPager
android:id="@+id/pager_test2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.myzoomproject.views.ZoomableRelativeLayout>
My Custom relative layout contains a viewpager and each single page in my viewpager contains 2-4 imageviews (one fullscreen imageview & a couple of clickable smaller imageviews). Zooming & panning the page works just fine.
Problem 1: But somehow I'm not able to set boundary limits for panning functionality. The page would pan off the screen on overscrolling.
Problem 2: Also, it seems that image-views are panned/translated only in drawing but not in actuality. because they are not clickable anymore the moment they move away from their original position on screen, & the clickable-coordinates remains confined to their original positions only.
I looked up several similar questions on SO link 1, link 2, link 3 but they all are based on ImageView zoom and not the custom-layout zoom.
So unlike them, I do not have a reference to my imageviews in my ZoomableRelativeLayout. Referencing the Imageviews, reading the bitmaps & displaying them is taken care of by other classes (MyPagerActivity & MyPagerFragment classes). Also, the solution in above mentioned links relies on matrix transformation, which i probably cannot use in my case.
Looking forward to any help on this.
Thanks.