Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoomed image plus ViewPage #38

Open
xmenxwk opened this issue Jul 25, 2013 · 8 comments
Open

Zoomed image plus ViewPage #38

xmenxwk opened this issue Jul 25, 2013 · 8 comments

Comments

@xmenxwk
Copy link

xmenxwk commented Jul 25, 2013

Assume there are 2 images in a ViewPager and when zooming the first one and try to pan(drag), the parent viewpager scrolls to second image instead of image panning. Using this.getParent().requestDisallowInterceptTouchEvent(true); inside onTouchEvent of does the trick but where should I allow it. If you can update the code, it would be awesome. I'm new to android.

@cargo8
Copy link

cargo8 commented Jul 25, 2013

You should extend the ImageViewZoom with your own ImageView subclass. Then try something like this:

this.setOnTouchListener(new OnTouchListener() {
@OverRide
public boolean onTouch(View v, MotionEvent event) {
if (getScale() > 1f) {
getParent().requestDisallowInterceptTouchEvent(true);
} else {
getParent().requestDisallowInterceptTouchEvent(false);
}
return false;
}
});

This should basically disallow paging whenever the image is scaled/zoomed beyond 1x. Thus, the user must zoom out in order to page.

@xmenxwk
Copy link
Author

xmenxwk commented Jul 25, 2013

Thank you, thats a good idea, but is it possible to do without zoom out, I mean when it reaches the max bound, let the parent allow.

@femosso
Copy link

femosso commented Jul 26, 2013

@xmenxwk
Copy link
Author

xmenxwk commented Jul 26, 2013

@femosso : Thats not what I meant. How do I know user reached to max bound ?

@whgreate
Copy link

did you solve this problem , i have this too !

@xmenxwk
Copy link
Author

xmenxwk commented Sep 11, 2013

Nope, I used the above method.

@saishneugi
Copy link

I know this is a very old post but i couldnt find a solution else where other than this so if anyones der please respond.@cargo8 solution works fine but the getScale() method seems to be deprecated in the present versions of android. So i used getScaleFactor() method. But it returns value as 1.0 however your resize your image. How can we check the actual scale value of the image?

@RaidenX5
Copy link

Try this :

imageviewtouch.setOnTouchListener(new View.OnTouchListener() {
@OverRide
public boolean onTouch(View view, MotionEvent motionEvent) {

            switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    Log.d("touchme", "down");
                    view.getParent().requestDisallowInterceptTouchEvent(true);
                    //view.requestDisallowInterceptTouchEvent(true);
                    break;
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_UP:
                    Log.d("touchme", "up");
                    view.getParent().requestDisallowInterceptTouchEvent(false);
                    //view.requestDisallowInterceptTouchEvent(false);
                    break;
                default:
                    break;
            }
            return false;
        }
    });

This will disable scrollview for taking touch event from imageviewtoich if the imageviewtouch still getting touch, will enable scroll on parent after imageviewtouch not receiving touch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants