简体   繁体   English

ViewPager在空白区域内触摸闪烁

[英]ViewPager Flickers on touch inside empty area

  • I have a scenario in view ViewPager is used to display multiple fragments depicting number of columns 我有一个视图中的场景ViewPager用于显示描述列数的多个片段
  • Now in tablet when there are only two pages / column inside the view pager , there remains empty area in the view pager after the two pages as view pager is occupying full screen of the tablet. 现在在平板电脑中,当视图寻呼机内只有两个页面/列时,由于视图寻呼机占据平板电脑的全屏,因此在两个页面之后视图寻呼机中仍有空白区域。
  • When the user touches this empty area the remaining pages start flickering scrolling back and forth in the screen. 当用户触摸该空白区域时,剩余页面开始在屏幕中来回滚动闪烁。
  • How to restrict user to touch in this empty area ? 如何限制用户在这个空白区域触摸? I also need to allow user swiping the pages to scroll , how to manage both the scenario. 我还需要允许用户滑动页面滚动,如何管理两个场景。

I just had this same scenario. 我只是有同样的情况。 My solution was to consume the touch event when there are less pages displaying than required to fill the viewpager 我的解决方案是在显示的页面少于填充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;
            }
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM