增加 SeekBar 的触摸优先级
我在 HorizontalScrollView
中有一个 SeekBar
,并且发现很难抓住手柄并移动它。如果我没有准确地触摸手柄,HorizontalScrollView
将接收并使用触摸事件。有没有办法提高 SeekBar
的优先级,以便它具有触摸事件的正常“范围”,或者这只是一个坏主意/设计,我应该避免它?
I have a SeekBar
inside a HorizontalScrollView
and am finding it very hard to grab the handle and move it. If I don't touch exactly on the handle, the HorizontalScrollView
will receive and consume the touch event. Is there a way to increase the priority of the SeekBar
so it will have the normal "range" for touch events or is this just a bad idea/design and I should avoid it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是解决此问题的另一种方法,无需扩展框架布局。
这个想法是在触摸 SeekBar 时禁用 HorizontalScrollView 的触摸事件。
因此,例如,当您初始化视图时,您可以定义如下内容:
有关详细信息,您可以阅读 ViewParent 类上的文档:
http://developer.android.com/reference/android /view/ViewParent.html#requestDisallowInterceptTouchEvent(boolean)
Here is an other way to fix this issue without extends a Frame layout.
The idea is to disable the touch event of the HorizontalScrollView when you touch the SeekBar.
So, when you initialize the view for example, you can define something like this:
For more information you can read the doc on ViewParent class:
http://developer.android.com/reference/android/view/ViewParent.html#requestDisallowInterceptTouchEvent(boolean)
我通过执行以下操作“解决”了它:
注意:我的滚动布局是可锁定的,如下所述:https ://stackoverflow.com/a/5763815/1067721 (只需注意我的答案稍微低一点,我发现这一点很重要)
然后我将我的搜索栏包裹在能够拦截触摸事件的 FrameLayout:
然后,在我的
Fragment
上,我实现了侦听器并让 SeekBar 消耗该事件:I "solved" it by doing the following:
NOTE: My scroll layout is lockable, as explained here: https://stackoverflow.com/a/5763815/1067721 (just pay atention to my answer a little bit lower, I found that bit to be important)
I then wrapped my seekbar in a FrameLayout able to intercept touch events:
And then, on my
Fragment
, I implemented the listener and let the SeekBar consume the event: