我尝试了很多解决方案的SO,但他们不是work.Finally,我重写dispatchTouchEvent()
功能,works.Complete版本是在gist 和关键代码是在这里。
@Override
public boolean dispatchTouchEvent(MotionEvent motionEvent) {
if(mHeaderView == null) return super.dispatchTouchEvent(motionEvent);
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
//if touch header not to consume the event
Rect rect = new Rect((int) mHeaderView.getX(), (int) mHeaderView.getY(), mHeaderView.getRight(), mHeaderView.getBottom());
if(rect.contains((int)motionEvent.getX(), (int)motionEvent.getY())){
isDownEventConsumed = false;
return isDownEventConsumed;
}else {
isDownEventConsumed = true;
return super.dispatchTouchEvent(motionEvent);
}
}else{
//if touch event not consumed, then move/up event should be the same
if(!isDownEventConsumed)return isDownEventConsumed;
return super.dispatchTouchEvent(motionEvent);
}
}
我能想到的防止标题消耗触摸事件的唯一方法是将其可见性设置为隐形。 – Max
想你@安德斯。我试过你的解决方案,但不工作... – Ninja