android - 启用点击项,即使在滚动 RecyclerView 时也是如此
问题描述
正常行为:当我们投掷滚动回收器视图时,项目将滚动,然后点击,RV 将停止滚动,不执行项目单击。
我需要什么:停止滚动+执行项目点击!
有什么绝招吗?
解决方案
我从这个 链接得到了答案
我想添加更多代码...
public class MyRecyclerView extends RecyclerView {
public MyRecyclerView(Context context) {
super(context);
}
public MyRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
//https://stackoverflow.com/a/46569656/8863321
boolean requestCancelDisallowInterceptTouchEvent = getScrollState() == SCROLL_STATE_SETTLING;
boolean consumed = super.onInterceptTouchEvent(e);
final int action = e.getActionMasked();
switch (action) {
case MotionEvent.ACTION_DOWN:
if( requestCancelDisallowInterceptTouchEvent ){
getParent().requestDisallowInterceptTouchEvent(false);
// stop scroll to enable child view get the touch event
stopScroll();
// not consume the event
return false;
}
break;
}
return consumed;
} }
这是非常罕见的情况,但这个技巧将来可能会对某人有所帮助!
推荐阅读
- c - C语言中的语法错误
- oracle - Oracle Apex Master Detail Report 和 Detail 报告,带有可供选择的单选按钮选项
- javascript - Mathjax 配置乳胶到中心
- go - 控制 Apache Beam 数据流管道中的并行性
- python - Microsoft Graph API:将 MSAL Python 守护程序应用程序限制为单个用户访问
- python - 为什么 Selenium 无法单击按钮列表中的按钮?
- javascript - 使用侧边栏向 Canvas 上的居中矩形添加一点填充
- javascript - typeorm 中的 find 函数返回带有 __underscores__ 的字段
- javascript - 搜索过滤html选择选项时jquery功能不起作用
- javascript - 如何将新行添加到反应表