通常情况下,当我按下一个键时,我可以得到两个动作:ACTION_DOWN
ACTION_UP
,但今天我遇到了一种情况,当我在遥控器中按right direction
时,我无法得到ACTION_DOWN
中的操作dispatchKeyEvent(event)
,只需获取操作ACTION_UP
。
是否因为其他一些方法拦截了这个事件?
实际上,调度代码是HorizontalScrollView
executeKeyEvent(KeyEvent event)
方法中的源代码:
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (!event.isAltPressed()) {
handled = arrowScroll(View.FOCUS_LEFT);
} else {
handled = fullScroll(View.FOCUS_LEFT);
}
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (!event.isAltPressed()) {
handled = arrowScroll(View.FOCUS_RIGHT);
} else {
handled = fullScroll(View.FOCUS_RIGHT);
}
break;
case KeyEvent.KEYCODE_SPACE:
pageScroll(event.isShiftPressed() ? View.FOCUS_LEFT : View.FOCUS_RIGHT);
break;
}
}