Android – viewpager touch blinks in a blank area

>I have a scene in the view. Viewpager is used to display multiple clips describing the number of columns > now, in the tablet, when there are only two pages / columns in the view pager, because the view pager occupies the full screen of the tablet, there is still a blank area in the view pager after two pages. > when the user touches the blank area, The remaining pages begin to scroll back and forth in the screen and flash. > How do you limit the user's touch in this blank area? I also need to allow users to scroll through the page and how to manage the two scenarios

resolvent:

I just have the same situation. My solution is to use touch events when fewer pages are 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;
            }
        }
    });

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>