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 4062792
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:38:36+00:00 2026-05-20T15:38:36+00:00

I have a Gallery with an adapter which supplies it ScrollViews as its child

  • 0

I have a Gallery with an adapter which supplies it ScrollViews as its child views.
I need to make sure that the touch events are handled correctly and as expected:

  1. When the user scrolls horizontally, the gallery scrolls horizontally.
  2. When the user scrolls vertically, the scroll view scrolls vertically.
  3. Both scrolls should never happen on the same gesture (the user must lift their finger to scroll the other view).
  4. Everything must scroll smoothly.

Without overriding any methods, the scroll view is the only thing that scrolls – the gallery never scrolls.

So I understand I need to use onInterceptTouchEvent(…) in the gallery to decide to take over a certain series of MotionEvents but I am unsure how to check if the touch is horizontal or vertical in nature.

  • 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-05-20T15:38:36+00:00Added an answer on May 20, 2026 at 3:38 pm

    OK, after some major fiddling and logcat hacking, here’s the solution:

    public class SwipeInterceptingGallery extends Gallery {
    
        private float mInitialX;
        private float mInitialY;
        private boolean mNeedToRebase;
        private boolean mIgnore;
    
        public SwipeInterceptingGallery(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        public SwipeInterceptingGallery(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public SwipeInterceptingGallery(Context context) {
            super(context);
        }
    
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
                float distanceY) {
            if (mNeedToRebase) {
                mNeedToRebase = false;
                distanceX = 0;
            }
            return super.onScroll(e1, e2, distanceX, distanceY);
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent e) {
            switch (e.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    mIgnore = false;
                    mNeedToRebase = true;
                    mInitialX = e.getX();
                    mInitialY = e.getY();
                    return false;
                }
    
                case MotionEvent.ACTION_MOVE: {
                    if (!mIgnore) {
                        float deltaX = Math.abs(e.getX() - mInitialX);
                        float deltaY = Math.abs(e.getY() - mInitialY);
                        mIgnore = deltaX < deltaY;
                        return !mIgnore;
                    }
                    return false;
                }
                default: {
                    return super.onInterceptTouchEvent(e);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Gallery control that displays a ListView as its adapter view. my
I have a Gallery, which has an adapter connects to it. In the getView
I've got an activity which has a gallery that is backed by an Adapter
I have a Gallery which contains WebView's as its children, when I scroll the
I have a gallery feeded by custom adapter using custom views as elements. I
I have photo gallery code that does image re-sizing and thumbnail creation. I use
I have custom gallery. Gallery represents items that are frame layout. There are one
I have a gallery that's loaded via a BaseAdapter . This works fine. I
Given that I have a Gallery object and Photo object. Gallery has many Photos.
Hi I have a gallery in my app which shows the image in an

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.