14

I had done pinch zoom with this polidea Zoomview.I have implemented this pinch zoom code in fragment page.

ZoomView zoomView;

//inside onCreateView method

zoomView= new ZoomView(getActivity());
zoomView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

zoomView.addView(gridTable);
zoomView.setRotationY(180);
gridviewlayout.addView(zoomView);

zoomview jar

Pinch Zoom in and Zoom out was working in gridview table page.But If I zoom-in a page and then scroll to next fragment page.After that when i go back to previous fragment page,the page is still in zoomed state.

What I am trying to do is reset the page in normal state when I move to next fragment page.

I searched a lot of samples.But Everything is related to Imageview.I didn't get any sample for pinch zoom in fragments with layout.

Anyone can help me with this.Thank you.

Stephen
  • 9,899
  • 16
  • 90
  • 137

3 Answers3

5

add below code to your fragment:

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if(!isVisibleToUser){
        if(mZoomView != null)mZoomView.zoomTo(1,0,0);
    }
}
mmlooloo
  • 18,937
  • 5
  • 45
  • 64
  • can you elaborate more.I can't get it.please explain with code for atleast one fragment. – Stephen May 12 '15 at 06:46
  • Each fragment must implement `ZoomViewListener` interface, then at the call of `void onZoomStarted(float zoom, float zoomx, float zoomy);` store those values somewhere then at onResume check those values and if those values are not dummies (-1) call ` zoomTo(final float zoom, final float x, final float y)` with those values. – mmlooloo May 12 '15 at 15:08
  • Can you create a sample project that has for example 3 fragments with your issue and upload it on github, I will then try to solve it and will email the result back to you in 1 or 2 days . – mmlooloo May 25 '15 at 08:31
  • I don't know how to upload in github.moreover i am trying to complete this task on today.If you please explain in detail with code for one fragment that's enough for me. – Stephen May 25 '15 at 08:35
  • i will post whole project on github in 5 minutes. – mmlooloo May 25 '15 at 09:16
  • very much thank you.That code helped me to solve my problem.you really saved my day.For polidea zoomview with fragment layout, I didn't seen any sample in internet.Every sample in google related to imageview.So this answer will be more worth. – Stephen May 25 '15 at 09:34
1

check this link...

ViewPager with detailed fragment lifecycle

that tutorial show to create listener on Pause and Resume Listener for each fragment. So, whenever you changed to other fragments, you can call zoom out in fragment's onPauseListener. This tutorial work for me.

Hope this work for you.

Hein Htet Aung
  • 844
  • 4
  • 16
1

override this method :

setPrimaryItem(ViewGroup container, int position, Object object)

this method is invoked each time the position changed. Now you know the is the visible fragment. that means you know what is not visible too (yeah I'm sherlock). Now you can set zoom value of all other fragments.(comparing previous index and new index maybe?)

It would be good for you to hold reference to your fragments and implement some methods for them like reset() or setZoom(float)

i hope this helps.

Ercan
  • 3,705
  • 1
  • 22
  • 37