幻灯片android与视图寻呼机指示器点击动作事件

时间:2016-08-03 06:03:34

标签: android android-viewpager slideshow motionevent

我从这个网站http://androidopentutorials.com/android-image-slideshow-using-viewpager/获得了一个带有视图寻呼机的幻灯片 我想设置Motion事件,如果最后一个项目的位置,我滑动该项目和位置返回到第一个。如何实现呢?

    ...
    mViewPager = (ViewPager) app.findViewById(R.id.view_pager);
    mIndicator = (CirclePageIndicator) app.findViewById(R.id.indicator);

    mIndicator.setOnPageChangeListener(new PageChangeListener());
    mViewPager.setOnPageChangeListener(new PageChangeListener());
    mViewPager.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.getParent().requestDisallowInterceptTouchEvent(true);
            switch (event.getAction()) {

            case MotionEvent.ACTION_CANCEL:
                Utils.log("ACTION_CANCEL " + products.size());
                break;

            case MotionEvent.ACTION_UP:
                // calls when touch release on ViewPager
                Utils.log("ACTION_UP " + products.size());
                if (products != null && products.size() != 0) {
                    stopSliding = false;
                    runnable(products.size());
                    handler.postDelayed(animateViewPager,
                            ANIM_VIEWPAGER_DELAY_USER_VIEW);
                }
                break;

            case MotionEvent.ACTION_MOVE:
                // calls when ViewPager touch
                Utils.log("ACTION_MOVE " + products.size());
                if (handler != null && stopSliding == false) {
                    stopSliding = true;
                    handler.removeCallbacks(animateViewPager);
                }
                break;
            }
            return false;
        }
    });
    ...

谢谢

1 个答案:

答案 0 :(得分:0)

这可能是重复的。看看下面的答案。您必须将此代码合并到您的代码中: https://stackoverflow.com/a/21371297/6663157