ViewPager Flickers when tapped inside an empty area

  • I have a script that ViewPager is used to display multiple fragments representing the number of columns.
  • Now on the tablet, when there are only two pages / column in the viewing pager, after viewing two pages, the empty panel remains in the viewing panel, since viewing the pager takes up the entire screen of the tablet.
  • When the user touches this empty area, the remaining pages begin to flicker, scrolling back and forth on the screen.
  • How to limit the user to touch in this empty area? I also need to allow the user to scroll through the pages to scroll through how to manage both scenarios.
+4
source share
1 answer

I had the same scenario. My solution was to consume a touch event when fewer pages were displayed than needed to populate the viewpager

viewPager.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { requestDisallowInterceptTouchEvent(true); // not sure if this is required PagerAdapter adapter = viewPager.getAdapter(); // consume the move event if we have only one page full - removes flickering artifact // getNumberOfPagesOnScreen() is a mehtod we have to get the number of pages we are going to display. ymmv if (adapter.getCount() <= adapter.getNumberOfPagesOnScreen() && event.getAction() == MotionEvent.ACTION_MOVE) { return true; } else { return false; } } }); 
+2
source

All Articles