Disabling & Enabling Paging In ViewPager in Android

前端 未结 3 1868
广开言路
广开言路 2020-12-14 10:36

I am using android compatibility package version 4 for displaying pdf pages in my app. I have used PagerAdapter & ViewPager for displaying pdf pages like horizontal scro

3条回答
  •  别那么骄傲
    2020-12-14 11:08

    I was having a similar problem with paging image files that need pinch to zoom. Simply put Needing a way to disable paging when image is zoomed in and enable it when the whole image is shown. I solved it like this and think you could do a similar thing. First extend : class MyViewPager extends ViewPager {...} And then in that class override following two methods

        @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (YOUR_CRITERIA_TOENABLE_DISABLE) {
            return true;
    
        } else {
            return super.onTouchEvent(event);
        }
    }
    
    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return super.onInterceptTouchEvent(event);
    }
    

    Be sure to use your view pager in xml layouts or dynamic creation from code.

提交回复
热议问题