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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:08:29+00:00 2026-06-05T22:08:29+00:00

I have a layout where I have a ScrollView and some stuffs. It looks

  • 0

I have a layout where I have a ScrollView and some stuffs. It looks like:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/welcome_scrol_lay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:background="@drawable/bg">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"  
        android:background="@drawable/bg"
        android:weightSum="100" >
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:orientation="vertical" 
            android:weightSum="100"
            android:background="@drawable/specialmapholder">
            <android.support.v4.view.ViewPager
                android:id="@+id/welcomeViewPager"
                android:layout_width="match_parent"
                android:layout_height="0dp" 
                android:layout_marginTop="15dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_weight="90"
                android:clickable="true" />
            <LinearLayout
                android:id="@+id/welcome_indicatorLayout"
                android:layout_width="match_parent"
                android:layout_height="0dp" 
                android:layout_weight="10"
                android:gravity="center" >
            </LinearLayout>
        </LinearLayout>
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:orientation="vertical">
            <TextView
                android:id="@+id/welcome_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:text="Large Text"
                android:textColor="@color/white"
                android:textStyle="bold"
                android:textSize="26dp"
                android:textAppearance="?android:attr/textAppearanceLarge" />
            <TextView
                android:id="@+id/welcome_body"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:text="Medium Text"
                android:textColor="@color/white"
                android:textSize="14dp"
                android:textStyle="bold"
                android:layout_marginTop="20dp"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>

As you can see I have a Viewpager in the ScrollView. I want to disable scroll when I touch ViewPager, because when I want to change picture page is scrolled. How can I disable the scroll function when I touch the ViewPager?

  • 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-05T22:08:30+00:00Added an answer on June 5, 2026 at 10:08 pm

    In Android, parents can consume child’s TouchEvents. In this case, the ScrollView consumes the TouchEvents of your ViewPager component. To avoid this behaviour, Android framework provides the onInterceptTouchEvent(MotionEvent).

    In your case, you have to subclass ScrollView and change the onInterceptTouchEvent(MotionEvent) method. You should change the onInterceptTouchEvent(MotionEvent), so that the ScrollView consumes the child’s event only when the user scrolls the ScrollView vertically.

    example implementation for ListView:

    public class VerticalListView extends ListView {
    
    private float mLastX;
    private float mLastY;
    private float mDiffX;
    private float mDiffY;
    
    public VerticalListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    
    public VerticalListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public VerticalListView(Context context) {
        super(context);
    }
    
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // reset difference values
                mDiffX = 0;
                mDiffY = 0;
    
                mLastX = ev.getX();
                mLastY = ev.getY();
                break;
    
            case MotionEvent.ACTION_MOVE:
                final float curX = ev.getX();
                final float curY = ev.getY();
                mDiffX += Math.abs(curX - mLastX);
                mDiffY += Math.abs(curY - mLastY);
                mLastX = curX;
                mLastY = curY;
    
                // don't intercept event, when user tries to scroll horizontally
                if (mDiffX > mDiffY) {
                    return false;
                }
        }
    
        return super.onInterceptTouchEvent(ev);
    }
    

    }

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

Sidebar

Related Questions

I have this layout: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=wrap_content android:orientation=horizontal android:gravity=left> <LinearLayout android:layout_width=wrap_content android:layout_height=wrap_content android:orientation=horizontal>
I have a layout which looks like this: <LinearLayout> <ImageView> android:width=wrap_content android:height:wrap_content ... </ImageView>
I have one main Activity with layout wrapped into ScrollView like this: <ScrollView android:layout_height=wrap_content
For Example, I have a layout like this: <ScrollView> <LinearLayout> <LinearLayout> ... </LinearLayout> <LinearLayout>
Simple problem: With the XML layout shown below, I have some views wrapped in
I have 2 layout xml files: highlights.xml and highlights_cell.xml. Here is a simplified version
I have an XML layout with some custom tabs, a heading, and a ProgressBar
I have a ScrollView layout like this, for example: <ScrollView> <Component1> <Component2> <Component3> <Component4>
I have a dialog with this content: <RelativeLayout android:layout_width=wrap_content android:layout_height=wrap_content > <ScrollView android:layout_width=fill_parent android:layout_height=wrap_content
I have a dynamically inflated layout. <TableLayout> <!-- Two more tablelayout here --> <ScrollView>

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.