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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:19:07+00:00 2026-05-25T11:19:07+00:00

I have a application that need event handling on a unusual way. For my

  • 0

I have a application that need event handling on a unusual way.

For my question, let me first explain a simple case that the current event handling system of Android don’t fits for me.

Supposing that I have a FrameLayout (that I’ll call ViewSwiper since now) that all Views added on it are MATCH_PARENT X MATCH_PARENT (that I’ll call PageView), it’s handles events by translating the actual View and replace it based on the direction of moving.
This component I already have done and work properly ( Using Animation to swipe views ).

But the problem is on that PageView I add on top of it, in case of ImageViews that return false on it’s onTouchEvent, the ViewSwiper will handle the events and let another PageView enter the screen, but if I add a ScrollView on that, all the events will be consumed by the Scroll and the ViewSwiper will not have chance to replace the PageView.

So I figured out that returning false onTouchEvent of the ScrollView the parent can assume it’s events, I wrote this sub-class of ScrollView to test it:

public class ScrollViewVertical extends ScrollView {
    public ScrollViewVertical(Context context) {
        super(context);
        setOverScrollMode(OVER_SCROLL_ALWAYS);
        setVerticalScrollBarEnabled(false);
    }

    public boolean onTouchEvent(MotionEvent evt) {
        super.onTouchEvent(evt);
        return false;
    }
}

But returning false make any further events to get dispatched to the parent, but I need these events for VERTICAL scrolling, so I have the idea to return falses only if the user are moving HORIZONTAL, that’s what my code looks like:

public class ScrollViewVertical extends ScrollView {
    private MovementTracker moveTracker;
    public ScrollViewVertical(Context context) {
        super(context);
        setOverScrollMode(OVER_SCROLL_ALWAYS);
        setVerticalScrollBarEnabled(false);
        moveTracker = new MovementTracker();
    }
    public boolean onTouchEvent(MotionEvent evt) {
        if (moveTracker.track(evt))
            if (moveTracker.getDirection() == Direction.HORIZONTAL)
                return false;

        return super.onTouchEvent(evt);
    }
}

PS: MovementTracker will returns true on track() after some events and tell on which direction the user is moving.

But in that case, the ScrollView keep receiving events since it’s returns true on the first events.

Any ideas on how can I handle the events on ViewSwiper when it’s child returns false (even if some trues are returned).

PS: I can give more info about this if needed, and accept different solutions also.

Based on answers I tried the following:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    onTouchEvent(ev);
    return intercept;
}

public boolean onTouchEvent(MotionEvent evt) {
    boolean x = super.onTouchEvent(evt);

    if (moveTracker.track(evt)) {
        intercept = moveTracker.getDirection() != Direction.VERTICAL;
        if (!intercept)
            getParent().requestDisallowInterceptTouchEvent(false);
    }

    return x;
}

Still nothing.

  • 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-25T11:19:08+00:00Added an answer on May 25, 2026 at 11:19 am

    try this in onTouchEvent() of the scrollview

         //if (evt.getAction() == MotionEvent.ACTION_MOVE) {
        if (moveTracker.track(evt)){
           if (moveTracker.getDirection() == Direction.VERTICAL){
              //Or the direction you want the scrollview keep moving
              getParent().requestDisallowInterceptTouchEvent(true);
    
                }
            } 
     return true;
    

    Update

    Please try the following to the custom Scrollview

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
    super.dispatchTouchEvent(ev);
        return false;
    }
    

    And nothing else

    This way i assume the MotionEvent will perform on both views. And since they don’t conflict (One is vertical the other one is Horizontal) this could work

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Cocoa application that records datestamps on events. I need to know
I have two application that need to talk to each other. App1 needs to
I have this application that need to do some things in protected paths (like
I have a web application that will need to access code behind methods as
We have an Excel application that I need to maintain that has shown his
Problem I have a UDPlistener application that I need to write a unit test
I have a PHP based application that I need to work on both a
I have an projector file/Flash application that I need to turn into an interactive
i have an application that has a dependancy on gdiplus. i need the application
I am in need of urgent help. I have an application that was working

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.