最近有一个需求,RecyclerView外层嵌套了一个LinearLayout,想实现点击整个LinearLayout都能响应一个事件,结果给LinearLayout和RecyclerView都加上点击事件(非itemClick)后,点击RecyclerView范围无效。可能是RecyclerView的item截获了click事件,阻止了点击的透传,做了以下处理解决
/*recyclerView3.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
layoutView3.performClick(); //模拟父控件的点击
}
return false;
}
});*/
如果采用ButterKnife事件绑定的方式则:
@OnTouch(R.id.recycler_view3)
public boolean onRvTouch(View v, MotionEvent event){
if (event.getAction() == MotionEvent.ACTION_UP) {
layoutView3.performClick(); //模拟父控件的点击
}
return false;
}