2015-12-10 86 views

回答

1

實現RecyclerView.OnItemTouchListener在你的電話就挖走了所有的觸摸事件上recyclerview

public class RecyclerViewDisabler implements RecyclerView.OnItemTouchListener { 

@Override 
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { 
    return true; 
} 

@Override 
public void onTouchEvent(RecyclerView rv, MotionEvent e) { 

} 

@Override 
public void onRequestDisallowInterceptTouchEvent(boolean) { 

} 
} 

啓用和禁用滾動:

RecyclerView recycleview = ... 
RecyclerView.OnItemTouchListener disabler = new RecyclerViewDisabler(); 

recycleview.addOnItemTouchListener(disabler); // scolling disable 
// do what you want to do at time of disable scrolling 
recycleview.removeOnItemTouchListener(disabler); // scrolling enabled again 
+0

謝謝你的回答。會嘗試。 – user3606902

+0

這也禁用onClick也 –

0
// You can set `onTouchListener` 

public class RecyclerViewTouch implements RecyclerView.OnItemTouchListener { 

    @Override 
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { 
     return true; 
    } 

    @Override 
    public void onTouchEvent(RecyclerView rv, MotionEvent e) { 

    } 

    @Override 
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 

    } 
} 

// Use it 
RecyclerView.OnItemTouchListener disable = new RecyclerViewTouch(); 
rView.addOnItemTouchListener(disable);  // disables scolling 
rView.removeOnItemTouchListener(disable);  // enable the scrolling 
0

你必須創建一個自定義佈局爲此,您可以禁用滾動

例如:

public class CustomLayoutManager extends LinearLayoutManager { 
private boolean isScrollEnabled = true; 

public CustomLayoutManager(Context context) { 
    super(context); 
} 

public void setScrollEnabled(boolean flag) { 
    this.isScrollEnabled = flag; 
} 

@Override 
public boolean canScrollHorizontally() { 
    //Similarly you can customize "canScrollVertically()" for managing horizontal scroll 
    return isScrollEnabled && super.canScrollHorizontally(); 
} 

這樣你可以禁用手動滾動

+0

但這也禁用非手動滾動 –