自定义View有时在使用时设置requestDisallowInterceptTouchEvent(true)无效

有一次Activity中使用了自定义view,并在代码中设置requestDisallowInterceptTouchEvent(true)的时候,发现设置后并没有消耗onTouch的几种事件。父view仍旧执行onTouch事件。后来网上搜索了一些资料,解决方法是:

重写自己用到的View的onTouchEvent方法,在其ACTION_DOWN的时候,调用父View的requestDisallowInterceptTouchEvent(true)方法设置,在ACTION_UP或者ACTION_CANCEL的时候,调用调用父View的requestDisallowInterceptTouchEvent(false)方法重置。

试了一把,可以解决!

谢谢博客
http://blog.csdn.net/jiwangkailai02/article/details/46666147

你可能感兴趣的:(自定义View有时在使用时设置requestDisallowInterceptTouchEvent(true)无效)