在RecyclerView中有一类item的布局是一个WebView,发现item的点击事件失效了,看了看才发现WebView也是ViewGroup,事件传递到WebView里面了,但要的效果是它作为一个item来消费事件,而不是它自身来消费,所以继承WebView,重写dispatchTouchEvent() ,return false将事件返回给父 View 的 onTouchEvent 进行消费,在布局中使用这个WebView就能简单的解决这个问题了,这类事件分发的问题都可以这样处理
public class QWebView extends WebView {
public QWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return false;
}
}