Android Seekbar-如何设置增量步骤

发布于 2025-02-12 02:15:34 字数 824 浏览 3 评论 0原文

我想使用seekbar选择时间。我有开学阶层和终结。时间差设置为seekbar.max(例如850分钟(INT 850))。我想将这一进度增加15分钟。

我该如何设置?我尝试设置seekbar.incrementprogressby(15),但它不起作用,它仍在增加1分钟。

我想实现的是,如果我有30分钟作为Max,并且我想移动拇指按钮,它将自动移动到中间,因此第一次增量基本上是15分钟(进度为50%)。

代码:

    maxDurationInMins = (((maxDate.time/1000)-(minDate.time/1000)).toInt())/60
    
    seekBar.progress = 0
    seekBar.max = maxDurationInMins
    seekBar.incrementProgressBy(15)
    seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener{
        override fun onProgressChanged(p0: SeekBar?, progress: Int, p2: Boolean) {
            updateProgressData(progress)
        }
        override fun onStartTrackingTouch(p0: SeekBar?) {}
        override fun onStopTrackingTouch(p0: SeekBar?) {}
    })

I want to use SeekBar to pick time. I have startDate and endDate. Difference in time is set as seekbar.max (could be for example 850 minutes(int 850)). And I want to increment this progress by 15 minutes.

How can I setup that? I tried to setup seekbar.incrementProgressBy(15) but its not working, its still incrementing by 1 minute.

What I want to achieve is that if I have 30 minutes as max and I want to move thumb button, it will automatically move to the middle so first increment is basically 15 minutes (progress 50%).

Code:

    maxDurationInMins = (((maxDate.time/1000)-(minDate.time/1000)).toInt())/60
    
    seekBar.progress = 0
    seekBar.max = maxDurationInMins
    seekBar.incrementProgressBy(15)
    seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener{
        override fun onProgressChanged(p0: SeekBar?, progress: Int, p2: Boolean) {
            updateProgressData(progress)
        }
        override fun onStartTrackingTouch(p0: SeekBar?) {}
        override fun onStopTrackingTouch(p0: SeekBar?) {}
    })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

窗影残 2025-02-19 02:15:34

只要您的最大时间可以通过您的增量除外而无需剩余时间,就可以将SeekBar.max设置为最大增量数。

interval = 15
seekBar.max = maxDurationInMins/interval

每当您现在在进度上做出反应时,将其乘以间隔。

As long as your max time is divisable by your increment without remainder, you could just set seekBar.max to the maximum number of increments.

interval = 15
seekBar.max = maxDurationInMins/interval

Whenever you now react on a progress change, multiply it by the interval.

旧城烟雨 2025-02-19 02:15:34

尝试这段

时间15分钟除以最大分钟(850)分钟,然后乘以100。15/850= 0.01764705882。 0.01764705882x100 = 1.76470588235

设置Seekbar concentage = 1.76470588235

公式

Time Percentage (%) = ( Spent Time [sec] / Max Time B [sec] ) × 100

Try this

Spent time 15 mins Divided by Max (850) mins then multiply 100. 15/850 = 0.01764705882. 0.01764705882x100 = 1.76470588235

Set the Seekbar parcentage = 1.76470588235

Formula

Time Percentage (%) = ( Spent Time [sec] / Max Time B [sec] ) × 100
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文