@Override public void onPageScrolled(int arg0, float arg1, int arg2) { CommUtil.logD(TAG, "onPageScrolled(" + arg0 + "," + arg1 + "," + arg2 + ")"); currentPageScrollIndex = arg0; currentPageScrollMove = arg1; } private int currentPageScrollIndex = -1; private float currentPageScrollMove = -1;
重點1:ide
@Override public void onPageSelected(int arg0) { CommUtil.logD(TAG, "onPageSelected(" + arg0+")"); setImageBackground(arg0 % mImgs.length); if(arg0 == mAllViews.size() -1) { //若是是拉倒最後顯示 繼續滑動查看詳情則返回上一個View vpViewPager.setCurrentItem(arg0-1); } }
重點2:post
vpViewPager.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_UP ){ CommUtil.logD(TAG, "vpViewPager MotionEvent.ACTION_UP"); if(currentPageScrollIndex == (mImgs.length-1) && currentPageScrollMove > 0.21) { //查看商品圖文詳情 BusProvider.getInstance().post(new SeeProductDetailEvent()); } } return false; } });