Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to slow down Android GridView scroll speed on button pressed? (LeanBack)

I'm working on an AndroidTV app, using the Leanback library.

I've got a few HorizontalGridView (which is an extension of RecyclerView) working correctly, however, scrolling through them by pressing and holding right|left button makes it scroll incredibly fast, too fast!

How can I slow down the speed at which it scrolls by leaving the button pressed?

like image 683
Francisco Noriega Avatar asked Oct 21 '25 14:10

Francisco Noriega


1 Answers

Do not listen your key event for some milli-time in your activity.

 @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        long current = System.currentTimeMillis();
        boolean res = false;
        if (current - mLastKeyDownTime < 300) {
            res = true;
        } else {
            res = super.onKeyDown(keyCode, event);
            mLastKeyDownTime = current;
        }
        return res;
    }
like image 72
A_rmas Avatar answered Oct 23 '25 02:10

A_rmas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!