我嘗試了很多解決方案的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