Android Seekbar-如何设置增量步骤
我想使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要您的最大时间可以通过您的增量除外而无需剩余时间,就可以将SeekBar.max设置为最大增量数。
每当您现在在进度上做出反应时,将其乘以间隔。
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.
Whenever you now react on a progress change, multiply it by the interval.
尝试这段
时间15分钟除以最大分钟(850)分钟,然后乘以100。15/850= 0.01764705882。 0.01764705882x100 = 1.76470588235
设置Seekbar concentage = 1.76470588235
公式
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