Setting any value for Gallery spacing will disable onKeyEvent

允我心安 提交于 2019-12-14 02:18:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!