mgamer
mgamer

Reputation: 14060

Disable touch events for ScrollView inside ViewPager in Android

I have ScrollViews as pages for ViewPager. I would like to disable touch events for that ViewPager completely. When I override onTouchEvent on my ViewPager class I only manage to prevent the horizontal scrolling but not the scrolling of the child ScrollViews.

How can I disable touch events entirely for ViewPager and all ScrollViews within it?

This is only a proof of concept for me. The next step is to prevent scrolling only for some part of that ViewPager.

Upvotes: 0

Views: 3296

Answers (1)

ePeace
ePeace

Reputation: 1997

Overwrite the onInterceptTouchEvent of your scrollview to either consume or ignore the event:

"Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here."

public class InterceptScrollView extends ScrollView {

public InterceptScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return false;
}

}

Upvotes: 1

Related Questions