设置Gallery间距的任何值都将禁用onKeyEvent

Teo*_*ing 2 android android-widget

当用户点击左或右按钮时,我试图使画廊向左或向右滚动动画.如果我使用下面的代码来调用keyevent来滚动图库,它会很好用:

gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT,  new KeyEvent(0, 0));
Run Code Online (Sandbox Code Playgroud)

要么

KeyEvent evtKey = new KeyEvent(0, KeyEvent.KEYCODE_DPAD_RIGHT);
gallery.dispatchKeyEvent(evtKey);
Run Code Online (Sandbox Code Playgroud)

但是,一旦我将任何值设置为Gallery间距,上面的代码就会停止工作.任何线索为什么会这样?

小智 5

这是我的答案.

                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);
            }
Run Code Online (Sandbox Code Playgroud)