Infinite Auto Scroll ListView with Scroll Speed Controlled

后端 未结 2 923
北恋
北恋 2020-12-25 08:19

I have been working on a ListViewidea where it keeps scrolling automatically with no user interaction and that is absolutely doable using the android APIs for i

2条回答
  •  时光取名叫无心
    2020-12-25 08:37

    I suggest, thath your adapter implemented in effective way. so this code is just scrolls listview

    you need to try another values of variables

    final long totalScrollTime = Long.MAX_VALUE; //total scroll time. I think that 300 000 000 years is close enouth to infinity. if not enought you can restart timer in onFinish()
    
    final int scrollPeriod = 20; // every 20 ms scoll will happened. smaller values for smoother
    
    final int heightToScroll = 20; // will be scrolled to 20 px every time. smaller values for smoother scrolling
    
    listView.post(new Runnable() {
                            @Override
                            public void run() {
                                    new CountDownTimer(totalScrollTime, scrollPeriod ) {
                                        public void onTick(long millisUntilFinished) {
                                            listView.scrollBy(0, heightToScroll);
                                        }
    
                                    public void onFinish() {
                                        //you can add code for restarting timer here
                                    }
                                }.start();
                            }
                        });
    

提交回复
热议问题