在 Android 中创建 SeekBar 位置弹出窗口
我的应用程序中有一个 SeekBar,我希望它的行为使得当用户拖动“拇指”时,拇指上方会出现一个弹出窗口(并在拖动拇指时跟随它),并且弹出窗口显示相应的位置SeekBar 的(或该位置可能代表的任何其他文本)。
有什么建议吗?
I have a SeekBar in my application, and I want it to behave so that when the user is dragging the 'thumb', a Popup appears above the thumb (and follows it as the thumb is dragged), and the Popup displays the corresponding positon of the SeekBar (or any other text that position may represent).
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看此博客
Check out this blog
拇指是可绘制的,因此解决方案可能是将拇指设置为可绘制的,其中包含拇指和带有文本的弹出窗口。这意味着您需要为滑块上的每个可能值提供一个可绘制/图标,并在每次值更改时更新它。环顾四周,我发现了这一点,这表明其他人在可绘制对象中需要文本时已经采用了这种方式: Convert String到可绘制
The thumb is a drawable, so a solution could be to set the thumb to a drawable that includes both thumb and popup with text. That means you would need a drawable/icon for each possible value on your slider, and update it every time the value changes. Looking around I found this, which suggests that others have gone that way when they needed text in their drawables: Convert String to Drawable
我为搜索栏后面的弹出窗口找到的解决方案是将文本视图放在搜索栏正上方的相对布局中。然后,在seekbar的onProgressChange中,通过一些调整来相应地设置textView的左边距
,效果很好!
干杯
The solution I found for this popup following the seek bar is to put the textview in a relative layout right above the seekbar. Then, in seekbar's onProgressChange, set the textView's left margin accordingly using
works great, with some tweaking!
cheers
这是所选答案的 Kotlin 版本和更多细节
Here's the Kotlin version of the chosen answer and a bit more detail