在滚动视图中使用搜索栏时出现问题
我在滚动视图内有一个搜索栏。当有人在滚动滑块更改期间意外触摸滑块时。我只想在拖动拇指时更改滑块值。谁能帮我解决这个问题吗?
I have a seek bar inside a scroll view.When some one accidentally touches the slider during scrolling slider changes. I want to change the slider value only when the i drag the thumb. Can anyone help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道有任何内置选项可以让您执行您想要的操作,但您可以轻松扩展默认的 SeekBar 实现并覆盖触摸事件的处理。基本实现看起来有点像这样:
由于 SeekBar 没有返回用于拇指的可绘制对象的
getThumb()
方法,因此有必要重写setTumb(...)
code> 来跟踪拇指集。您可以查找 SeekBar 的源代码,发现它总是很好地调用此方法来设置拇指可绘制 - 对我们来说很方便。 :)触摸事件的处理基本上非常简单:只需测试触摸坐标是否在拇指可绘制的边界框内即可。显然,如果您有圆形拇指,您可以应用稍微不同的测试,但想法应该很清楚。如果触摸事件不在拇指上,则只需返回正在处理的事件并且不传播它。
I'm not aware of any builtin option that allow you to do what you're looking for, but you can easily extend the default SeekBar implementation and override the handling of touch events. A basic implementation will look somewhat like this:
As SeekBar does not have a
getThumb()
method that returns the drawable used for the thumb, it's necessary to overridesetTumb(...)
to keep track of the thumb set. You can look up the source for SeekBar and see that it always nicely calls this method to set the thumb drawable - convenient for us. :)The handling of touch events is basically very simple: just do a test whether the touch coordinates are inside the bounding box of the thumb drawable. Obviously, if you have circular thumb, you could apply a slightly different test, but the idea should be clear. If the touch event was not on the thumb, simply return it being handled and don't propagate it.