Setting any value for Gallery spacing will disable

2019-07-20 01:31发布

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条回答
Viruses.
2楼-- · 2019-07-20 01:46

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);
            }
查看更多
登录 后发表回答