How can I make an Android seek-bar move smoothly?

前端 未结 5 1344
故里飘歌
故里飘歌 2021-02-04 11:05

I\'m trying to make a SeekBar move more smoothly than just jumping straight to the position. I\'m doing this as I\'ve got a SeekBar with 3 options for a slider-type implementati

5条回答
  •  太阳男子
    2021-02-04 11:37

    You don't need to build anything by yourself just user android animation it will do the thing for you

    The code written in kotlin

        mySeekbar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
                //Todo: code
            }
    
            override fun onStartTrackingTouch(seekBar: SeekBar?) {
            }
    
            override fun onStopTrackingTouch(seekBar: SeekBar) {
                if (seekBar.progress > 70) {
                    ObjectAnimator.ofInt(seekBar, "progress", 100).setDuration(100).start()
                } else if (seekBar.progress < 30) {
                    ObjectAnimator.ofInt(seekBar, "progress", 0).setDuration(100).start()
                } else {
                    ObjectAnimator.ofInt(seekBar, "progress", 50).setDuration(100).start()
                }
            }
        })
    

提交回复
热议问题