Zoomed image plus ViewPage
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.
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.
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.
Take a look at this:
http://stackoverflow.com/questions/14764603/how-to-intercept-touch-events-from-viewpager-onpagechangelistener
@femosso : Thats not what I meant. How do I know user reached to max bound ?
did you solve this problem , i have this too !
Nope, I used the above method.
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?
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.