2015-12-10 55 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

但这也禁用非手动滚动 –