2014-10-27 33 views
0

關於如何阻止在ViewPager中滑動有很多問題和解決方案。ViewPager塊向前頁

實施例:Control which directions the ViewPager can be scrolled, dynamically with UI feedback

但是我想在一個特定頁面(I有一個表格,並註冊按鈕,帶翻頁編程)只塊向前滑動

示例: 第1頁 - >滑動< - 頁面2 - >滑動< - 頁面3(表單) - >按鈕 - > Page 4

試圖用onInterceptTouchEvent和onInterceptTouchEvent方法擴展類ViewPager,但是這樣做時我無法使按鈕工作,因爲所有內容都被讀爲MotionEvent.ACTION_MOVE,所以不知道何時讓事件通過或何時使用返回false;

+1

羅馬Nurik的嚮導尋呼機聽起來就像你在找什麼https://github.com/romannurik/Android-WizardPager – reactivemobile 2014-10-27 16:00:38

回答

0
 


import android.content.Context; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.MotionEvent;

public class CustomViewPager extends ViewPager {

private boolean enabled; private boolean blockSwipe = false;

public CustomViewPager(Context context, AttributeSet attrs) { super(context, attrs); this.enabled = true; }

@Override public boolean onTouchEvent(MotionEvent event) { if (this.enabled) { return super.onTouchEvent(event); }

return false; }

public void setBlockSwipe(boolean blockSwipe) { this.blockSwipe = blockSwipe; }

@Override public boolean onInterceptTouchEvent(MotionEvent event) { if (blockSwipe) return false; else return super.onInterceptTouchEvent(event); }

}

+0

添加此類和使用viewpager參考...塊刷卡只是ex viewPager.setBlockSwipe(true); – 2015-08-19 14:04:44