2

in an android app I am using a sliding menu to the left: https://github.com/jfeinstein10/SlidingMenu

inside one of the activity, I have a ViewPager:

<android.support.v4.view.ViewPager
      android:id="@+id/image_pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

I load multiple images view in the pager from the adapter to scroll between them.

However I am facing a conflict in scrolling.

When I swipe to the left everything works fine, the next image gets displayed.

But when I swipe to the right, the sliding menu will open, since its his behavior.

Can I make it in a way that swiping on the View Pager does not propagate to the sliding menu?

I tried to return true in the OnTouchListener of the pager, but the sliding menu is still opening, and now the slider doesn't work anymore.

            viewPager.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            return true;
        }
    });

Thanks for any help

Y2theZ
  • 10,162
  • 38
  • 131
  • 200

2 Answers2

4

check accepted answer here

The feinstein slidingmenu can be configured so it only reacts to gestures that begin at the edge of the screen. That should allow your other handler to be the sole delegate of swipes that originate anywhere NOT on the extreme edge of the screen.

I believe that you can set these in "class BaseActivity extends SlidingFragmentActivity"

Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
1

I have a better solution:

Set an OnTouchListener for you ViewPager and disable the SlidingMenu on ACTION_DOWN, enable the SlidingMenu on ACTION_UP and ACTION_CANCEL.

Here is the code:

ViewPager mPager;

// Find your SlidingMenu here.
SlidingMenu mSlidingMenu;

mPager.setOnTouchListener(new View.OnTouchListener() {
     @Override
     public boolean onTouch(View v, MotionEvent event) {
         switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                   mSlidingMenu.setSlidingEnabled(false);
                   break;
              case MotionEvent.ACTION_UP:
              case MotionEvent.ACTION_CANCEL:
                   mSlidingMenu.setSlidingEnabled(true);
                   break;
         }
         return false;
    }
}
Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
Lei Guo
  • 2,550
  • 1
  • 17
  • 22