2015-12-21 36 views
1

我的應用程序中出現小錯誤。如何在SwipeRefreshLayout中設置增量

這是我的應用程序結構: enter image description here

當我開始滾動用於移動到下一個頁面中ViewPagerSwipeToRefreshLayout抓我刷卡,我不能改變頁面。

如何爲SwipeRefreshLayout設置增量?

+0

請問您能分享一下您的代碼嗎? –

回答

2

我通過擴展SwipeRefreshLayout解決了這個問題,並且禁止攔截水平滾動,如下所示。這是我在stackoverflow上找到的一個修改過的代碼。

public class PullToRefresh extends SwipeRefreshLayout { 

    private final int mTouchSlop; 
    private float mTouchDownX; 

    public PullToRefresh(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); 
    } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent event) { 
     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       mTouchDownX = event.getX(); 
       break; 
      case MotionEvent.ACTION_MOVE: 
       if (Math.abs(event.getX() - mTouchDownX) > mTouchSlop) { 
        return false; 
       } 
       break; 
     } 
     return super.onInterceptTouchEvent(event); 
    } 

}