Android ViewPager只在左侧滚动

时间:2015-05-11 13:05:48

标签: java android android-fragments scroll android-viewpager

在我的情况下,我有一个自定义视图寻呼机。我希望它只滚动到左侧,右侧滚动被禁用。我试过了:

pager.setOnPageChangeListener(new OnPageChangeListener() {

        int Pos = pager.getCurrentItem();

        @Override
        public void onPageScrolled(int position, float positionOffset,
                int positionOffsetPixels) {
            mCurrentPage = pager.getCurrentItem();
            if (position == mCurrentPage) {
                // It's gone to right.
                if (positionOffset > -4) {
                    // setPage(position + 1);
                    pager.setCurrentItem(position + 1);
                }
                // Not yet.
                else {
                    // setPage(position);
                    pager.setCurrentItem(position);
                }
            } else {
                // It's gone to left.
                if (positionOffset < 0.5) {
                    // setPage(position);
                    pager.setCurrentItem(position);
                }
                // Not yet.
                else {
                    // setPage(position + 1);
                    pager.setCurrentItem(position + 1);
                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPageSelected(int position) {
            // mCurrentPage = position;
            // pager.setCurrentItem(position);
        }
    });

但它没有用,我也检查了

How to disable ViewPager from swiping in one direction

How to know ViewPager has scrolled half the screen in android

Viewpage stop swiping in a certain direction

但我无法使其发挥作用。

0 个答案:

没有答案