2

I'm trying to achieve something pretty specific and cannot find a proper answer in SO or Google.

I have a ViewPager displaying fragments on swipe (left <-> right), working perfectly.

I need the entire screen to intercept swipe-down touch events, and the ViewPager to keep intercepting left-right swiping.

Basically, if the user swipe in left <-> right direction on the ViewPager, it handles it normally, but if user swipe down (on ViewPager or anywhere else), I need to trigger other behavior.

I've read a lot about onInterceptTouchEvent(), but I don't really understand how it works...

Here's my viewpager_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/dialog_root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.TabLayout
            android:id="@+id/dialog_tablayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorDark"
            app:tabSelectedTextColor="@color/colorPrimary"
            app:tabIndicatorColor="@color/colorPrimary"
            app:tabIndicatorHeight="1dp"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/dialog_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorDark"/>
    </LinearLayout>
</RelativeLayout>

I didn't post any of my Java code, because it's a simple implementation of ViewPager, but if you need any additional information I will be glad to edit my question.

Thank you!

Keysaw
  • 227
  • 4
  • 19
  • See this library will help you [DoubleViewPager](https://github.com/juliome10/DoubleViewPager) – Mohamed Mohaideen AH Jan 24 '18 at 16:19
  • Thank you, but that's not quite what I want. I need to get swipe-down events on the root layout, not a ViewPager that works in both directions. The event I want to trigger when swiping down has nothing to do with ViewPager behavior. – Keysaw Jan 24 '18 at 16:51
  • See this answer might helpful https://stackoverflow.com/a/12938787/4824088 – Mohamed Mohaideen AH Jan 25 '18 at 07:15

0 Answers0