本文介绍了禁用 RecyclerView 的触摸事件(以防止用户触摸)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用中有一个 RecyclerView,它显示数据.我想禁用 RecyclerView 的用户触摸事件.我已经尝试了下面的代码,但它不起作用.
I have a RecyclerView in my app and it displays data. I want to disable user touch events of RecyclerView. I have tried the below code but it does not work.
recyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
请帮帮我.
推荐答案
因为我前几天有一个类似的用例,现在偶然发现了这个问题:
你可以添加任何一个
As I had a similar use case a few days ago and stumbled upon this question just now:
you can add either
到您的 RecyclerView.
to your RecyclerView.
使用RecyclerView.SimpleOnItemTouchListener
的示例:
recyclerView.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
// true: consume touch event
// false: dispatch touch event
return true;
}
});
当我的 SwipeRefreshLayout
通过查询 swipeLayout.isRefreshing()
进行后台工作时,我消耗了触摸事件.
I consumed the touch event while my SwipeRefreshLayout
was doing background work by querying swipeLayout.isRefreshing()
.
这篇关于禁用 RecyclerView 的触摸事件(以防止用户触摸)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!