一个搜索栏增加触摸优先 [英] Increasing touch priority of a SeekBar
问题描述
我有一个搜索栏
在 HorizontalScrollView
和我发现它很难抓住手柄,移动它。如果我完全不触及手柄, HorizontalScrollView
将接受和使用触摸事件。是否有增加的优先级的方式搜索栏
所以它有触摸事件的正常范围或者这只是一个坏主意/设计,我应该避免?
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?
推荐答案
我做下面的解决是:
注意:我的滚动布局上锁,按如下说明: http://stackoverflow.com/ A /1067721分之5763815(只需付atention给我的回答有点低,我发现一点很重要)
NOTE: My scroll layout is lockable, as explained here: http://stackoverflow.com/a/5763815/1067721 (just pay atention to my answer a little bit lower, I found that bit to be important)
我再包我在的FrameLayout搜索栏能够拦截触摸事件:
I then wrapped my seekbar in a FrameLayout able to intercept touch events:
public class InterceptFrameLayout extends FrameLayout {
private OnTouchListener mListener;
public InterceptFrameLayout(Context context) {
super(context);
}
public InterceptFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public InterceptFrameLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent (MotionEvent ev) {
return onTouchEvent(ev);
}
@Override
public void setOnTouchListener (View.OnTouchListener l) {
mListener = l;
}
@Override
public boolean onTouchEvent (MotionEvent ev) {
if (mListener != null) {
return mListener.onTouch(this, ev);
} else {
return super.onTouchEvent(ev);
}
}
}
然后,在我的片段
,我实现了听众,让搜索栏消耗事件:
And then, on my Fragment
, I implemented the listener and let the SeekBar consume the event:
volWrapper.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
mHostingScroll.setScrollable(false);
break;
}
case MotionEvent.ACTION_UP: {
mHostingScroll.setScrollable(true);
break;
}
}
return volumeBar.onTouchEvent(event);
}
});
这篇关于一个搜索栏增加触摸优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!