0

I have a view behind a ViewPager. This view slides up and down vertically, using an OnTouchListener. This works fine when part of the view is shown, but I'd like to make it so users can swipe downward from the top of the ViewPager to reveal this view. I've tried subclassing ViewPager and returning false in onInterceptTouchEvent, but it did not work. I've also tried adding this OnTouchListener to the ViewPager itself as a hack but this didn't work either.

The images below represent what I'm trying to achieve.

Collapsed View behind ViewPager

Collapsed View behind ViewPager

Swiping View from behind the ViewPager

Swiping View from behind the ViewPager

This is the simple layout code I've been testing with:

 <?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:layout_width="match_parent"
     android:layout_height="match_parent">
     <View
          android:id="@+id/content"
          android:background="@android:color/black"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/>
     <android.support.v4.view.ViewPager
          android:id="@+id/viewPager"
          android:layout_width="match_parent"
          android:layout_height="128dp" />
 </RelativeLayout>
Arjun saini
  • 4,223
  • 3
  • 23
  • 51
snotyak
  • 3,709
  • 6
  • 35
  • 52

1 Answers1

0

Try simulating the touch event of your View on touch event of your ViewPager, follow this for simulating the touch event, How to programmatically trigger the touch event in android?. Let me know if this works.

Community
  • 1
  • 1
karan vs
  • 3,044
  • 4
  • 19
  • 26
  • I basically added an `onTouchListener` to the `ViewPager` to do the exact same stuff as the view behind it. I _thought_ I did this earlier, but I actually put the `onTouchListener` on its parent view (the layout indeed is more complicated than the xml above, I just made a booboo) :/ – snotyak Jul 22 '16 at 13:47