Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:59:11+00:00 2026-06-15T19:59:11+00:00

I am trying to implement a Gallery of images using ViewPager. Also, to implement

  • 0

I am trying to implement a Gallery of images using ViewPager. Also, to implement zoom feature in that, I am using TouchImageView from github. I have also tried using ZoomableImageView.

But, the problem is, if I zoom the image & if I scroll the image , then instead of image, ViewPager is getting scrolled & next view of ViewPager is getting loaded.

If I zoom the image then if I scroll that, then image has to move instead of ViewPager

ViewPager’s next view has to load only if reach the end of the zoomed image. How to do that?

I am not able to find that.If I touch & drag the image diagonally, only then image is getting moved. or else ViewPager’s drag is getting invoked.

ps: this is not duplicate. Zooming is done. But the problem is after image zooming.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:59:12+00:00Added an answer on June 15, 2026 at 7:59 pm

    Yes I too had the same problem not with TouchImageView.

    Too solved the problem what i did is disabled the ViewPager when my view is getting the focus.

    public class EnableDisableViewPager extends ViewPager {
    
        private boolean enabled = true;
    
        public EnableDisableViewPager(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent arg0) {
            if(enabled)
                return super.onInterceptTouchEvent(arg0);
    
            return false;
        }
    
        public boolean isEnabled() {
            return enabled;
        }
    
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
    }
    

    so in TouchImageView implement your listener to trigger an event whether its zooming or dragging.

    set listener to your view object in your Activity. So when those event occur just disable the view Pager.

    Note: you will also need a mouse up event to enable the viewpager.

    EDITED

    This will work only for Zoom, so for ViewPager to swipe pages you should zoom back to original.

    Add these code to your TouchImageView

        public class TouchImageView extends ImageView {
    
            ...
        private TouchEventListener touchEventListener;
    
            private void sharedConstructing(Context context) {
                ...
    
                setOnTouchListener(new OnTouchListener() {
    
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        ...
                            case MotionEvent.ACTION_UP:
                                ...
                                if(touchEventListener != null)
                                {
                                    if(saveScale == 1.0)
                                        touchEventListener.onZoomToOriginal();
                                    else
                                        touchEventListener.onZoom();
                                }
                                break;
    
                            ...
                        }
                        ...
                    }
    
                });
            }
    
            ...
    
    public TouchEventListener getTouchEventListener() {
            return touchEventListener;
        }
    
        public void setTouchEventListener(TouchEventListener touchEventListener) {
            this.touchEventListener = touchEventListener;
        }
    
    
            public interface TouchEventListener 
            {
                void onZoom();
                void onZoomToOriginal();
            }
        }
    

    BETTER SOLUTION

    We could achieve this without extending ViewPager to a new Class by using the method given below.

    requestDisallowInterceptTouchEvent(true);
    

    And with this we could swipe without zooming out to original position as we see in Gallery and many other apps.

    public class TouchImageView extends ImageView {
    
            ...
    private void stopInterceptEvent()
    {
        getParent().requestDisallowInterceptTouchEvent(true);
    }
    
    private void startInterceptEvent()
    {
        getParent().requestDisallowInterceptTouchEvent(false);
    }
    
    private void sharedConstructing(Context context) {
        super.setClickable(true);
        this.context = context;
        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
        matrix.setTranslate(1f, 1f);
        m = new float[9];
        setImageMatrix(matrix);
        setScaleType(ScaleType.MATRIX);
    
        setOnTouchListener(new OnTouchListener() {
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                mScaleDetector.onTouchEvent(event);
    
                matrix.getValues(m);
                float x = m[Matrix.MTRANS_X];
                float y = m[Matrix.MTRANS_Y];
                PointF curr = new PointF(event.getX(), event.getY());
    
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        last.set(event.getX(), event.getY());
                        start.set(last);
                        mode = DRAG;
                        stopInterceptEvent();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        if (mode == DRAG) {
                            float deltaX = curr.x - last.x;
                            float deltaY = curr.y - last.y;
                            float scaleWidth = Math.round(origWidth * saveScale);
                            float scaleHeight = Math.round(origHeight * saveScale);
                            if (scaleWidth < width) {
                                deltaX = 0;
                                if (y + deltaY > 0)
                                    deltaY = -y;
                                else if (y + deltaY < -bottom)
                                    deltaY = -(y + bottom); 
                            } else if (scaleHeight < height) {
                                deltaY = 0;
                                if (x + deltaX > 0)
                                    deltaX = -x;
                                else if (x + deltaX < -right)
                                    deltaX = -(x + right);
                            } else {
                                if (x + deltaX > 0)
                                    deltaX = -x;
                                else if (x + deltaX < -right)
                                    deltaX = -(x + right);
    
                                if (y + deltaY > 0)
                                    deltaY = -y;
                                else if (y + deltaY < -bottom)
                                    deltaY = -(y + bottom);
                            }
    
                            if(deltaX == 0)
                                startInterceptEvent();
                            else
                                stopInterceptEvent();
    
                            matrix.postTranslate(deltaX, deltaY);
                            last.set(curr.x, curr.y);
                        }
                        break;
    
                    case MotionEvent.ACTION_UP:
                        mode = NONE;
                        int xDiff = (int) Math.abs(curr.x - start.x);
                        int yDiff = (int) Math.abs(curr.y - start.y);
                        if (xDiff < CLICK && yDiff < CLICK)
                            performClick();
                        startInterceptEvent();
                        break;
    
                    case MotionEvent.ACTION_POINTER_UP:
                        mode = NONE;
                        break;
                }
                setImageMatrix(matrix);
                invalidate();
                return true; // indicate event was handled
            }
    
        });
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What am I trying to implement? A gallery of images using ViewPager. I choose
I have been having this annoying problem when trying to implement a picture gallery
I am trying to make a ImageButton that opens a Gallery with images. I
I am trying to create a PHP function that downloads images from a webpage
I am trying to implement a gallery which always starts from left rather than
I'm trying to show images in the specific folder using default Android Gallery. I
I'm trying to implement this gallery on my site: http://tympanus.net/Tutorials/SweetThumbnails/ I'm using the CSS
I am trying to write a photo gallery that show images with GridView. Images
I am trying to make a gallery of images, i have written the code
I am trying to implement a jquery gallery plugin in a force.com site. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.