Reduce speed of smooth scroll in scroll view

后端 未结 5 1030
栀梦
栀梦 2021-02-03 19:44

I have a scroll View. I performed smooth-scroll.using smoothScrollBy().It all works fine, but I want to change the duration of the smooth-scroll. Smooth-scroll happens very fast

5条回答
  •  情歌与酒
    2021-02-03 20:20

    This is how I achieved a smooth vertical scroll (like movie credits). This also allows the user to move the scroll up and down and allow it to continue scrolling when they let go. In my XML, I encapsulated my TextView inside of a ScrollView called "scrollView1". Enjoy!

        final TextView tv=(TextView)findViewById(R.id.lyrics);
        final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView1);
        Button start = (Button) findViewById(R.id.button_start);
        Button stop = (Button) findViewById(R.id.button_stop);
        final Handler timerHandler = new Handler();
        final Runnable timerRunnable = new Runnable() {
            @Override
            public void run() {
                scrollView.smoothScrollBy(0,5);         // 5 is how many pixels you want it to scroll vertically by
                timerHandler.postDelayed(this, 10);     // 10 is how many milliseconds you want this thread to run
            }
        };
    
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               timerHandler.postDelayed(timerRunnable, 0);
            }
        });
    
        stop.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                timerHandler.removeCallbacks(timerRunnable);
            }
        });
    

提交回复
热议问题