I am using ViewPager
and WebView
to present HTML
contents as an eBook. On some pages of the ViewPager I am allowing the TouchEvent
to be handled by the WebView and on some pages I am letting the ViewPager handle the TouchEvent
by itself by overriding the onInterceptTouchEvent
method in the ViewPager
(some pages are having TextViews
and Buttons
without WebView
1st and last page here). Here is code for the same-
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1)
return false;
else {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
return false;
}
return true;
}
}
I am again disallowing the scrolling by setting OnTouchListener
on the WebView
using the following code-
contentView.setOnTouchListener((v, event) -> {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_MOVE) {
((BigBeeViewPager) v.getParent().getParent()).onInterceptTouchEvent(event);
}
return true;
});
Problem I am facing is - When I am trying to swipe the ViewPager from the middle of the pages it doesn't work. I have to start swiping from the end of the pages. However it works fine for the pages which are not having WebView
How to allow it to start swiping from the anywhere in the pages.
This behaviour is similar to Gmail Android App where ViewPager
is containing the WebView and Swiping is available from any where. I am not able to figure out how they have done it.
Note - When I am intercepting all TouchEvent
to the WebView
it disables the long click and text selection too, which is not desirable.
Thanks in advance for the help.
Here you go man - an old problem with a nice solution.
Take a look here Scroll webview horizontally inside a ViewPager
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With