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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:06:42+00:00 2026-06-12T21:06:42+00:00

I use android.support.v4.app.FragmentActivity for create a app with multi fragment/panels that can be access

  • 0

I use android.support.v4.app.FragmentActivity for create a app with multi fragment/panels that can be access by drag/swipe between different part of the app.
In one of my fragment I has a zoomable view and my problem is in case I is on the zoomable view I will prevent the use for drag/swipe to a other fragment.

I has try to hack into android.support.v4.view.ViewPager for get the action from on Touch event but not work.

I has try all of this case but not work:
(All code is a a part of subclass to android.support.v4.view.ViewPager)

Case 1:

// Not working
@Override
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    if (isPreventDrag()) {
        super.onPageScrolled(position, 1, 0);
    } else {
        super.onPageScrolled(position, offset, offsetPixels);
    }
}

Case 2:

// Work but stop all event include the event to the target image view.
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            lastX = ev.getX(); // float 
            lockScroll = false;
            return super.onInterceptTouchEvent(ev);
        case MotionEvent.ACTION_MOVE:
            this.lockScroll = this.isPreventDrag();
            break;
    }
    if (lockScroll) {
        ev.setLocation(lastX, ev.getY());
        return super.onInterceptTouchEvent(ev);
    } else {
        return super.onInterceptTouchEvent(ev);
    }
}

Case 3:

// Work good, but by some unknown error I can drag the screen
// some pixels before this stop the event.
@Override
public boolean onTouchEvent(MotionEvent ev) {

    if (this.isPreventDrag()) {
        return true;
    } else {
        return super.onTouchEvent(ev);
    }
}

I want a easy way to deactivate stop or deactivate if the use is allow to switch to a other Fragment.

Here is a working code for me, I don’t know what error I do before.

// This work for me,
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (this.isPreventDrag()) {
        return false;
    } else {
        return super.onInterceptTouchEvent(ev);
    }
}
  • 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-12T21:06:44+00:00Added an answer on June 12, 2026 at 9:06 pm

    I use this ViewPager class to control ‘swipeability’ of viewpager:

    public class MyViewPager extends ViewPager {
    
        public MyViewPager(Context context) {
            super(context);
        }
    
        public MyViewPager(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        private boolean blockSwipe = false;
        public void setBlockSwipe(boolean blockSwipe) {
            this.blockSwipe = blockSwipe;
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent arg0) {
            if (blockSwipe)
                return false;
            else 
                return super.onInterceptTouchEvent(arg0);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: import android.support.v4.app.FragmentActivity; import android.support.v4.app.Fragment; public void onCreate(Bundle savedInstanceState) {
I'm trying to add a support.v4.app.Fragment to a PreferenceActivity header, like so: <header android:fragment=com.example.SupportFragmentSubClass
I am looking to use NavUtils (http://developer.android.com/reference/android/support/v4/app/NavUtils.html) in the v4 android compatibility libraries for
I'm trying to support as many android devices as I can for the app
I am trying to use the compability APIs (android.support.v4.app) I have downloaded them and
Does Android support pthreads? And why when i use -pthread option i see the
Does Android support virtual memory concept? I read it does use paging but not
What font file types does Android support (for use with Typeface.createFromAsset, for instance)? I
I use class from How to support Arabic text in Android? to show Arabic
I'm making a new Android app that essentially mirrors data available on our website.

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.