问题
I am trying to make the Gallery scroll with animation to left or right when user click on either the left or right buttons. It works well if I use the below code to invoke the keyevent to scroll the gallery:
gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, new KeyEvent(0, 0));
or
KeyEvent evtKey = new KeyEvent(0, KeyEvent.KEYCODE_DPAD_RIGHT);
gallery.dispatchKeyEvent(evtKey);
But once I set any value to the Gallery spacing, the code above stop working. Any clue why this is so?
回答1:
This is my answer.
if( isMoveRight() ) {
gallery.onScroll(null, null, spacing+1, 0);
gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
}
else {
gallery.onScroll(null, null, -1*(spacing+1), 0);
gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, null);
}
来源:https://stackoverflow.com/questions/5027205/setting-any-value-for-gallery-spacing-will-disable-onkeyevent