我使用第三方组件(AndroidSideMenu),它允许将整个活动向右拖动以显示侧边菜单。
在布局的主(非菜单)部分,我有一个水平的SeekBar。 问题是当我开始拖动SeekBar按钮时,整个布局随之拖动,因为SlideHolder组件也响应了拖动事件。
我不确定如何在Android中管理触摸事件,但有没有办法在SeekBar处理事件后停止事件,以便它们不会到达父容器? 因此,当您拖动Seekbar时,整个屏幕(父级)必须保持不变,但是当您在SeekBar外部拖动时,它仍然必须按侧边菜单的要求工作?
由于
答案 0 :(得分:1)
在SeekBar的容器中,创建并应用(向seekBar)OnTouchListener,如下所示:
private final OnTouchListener onTouchListener = new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
// If the View in question isn't a child of the seekBar and
// isn't the seekBar itself, then return and don't consume the event.
if ( (seekBar.findViewById(v.getId()) == null) &&
(v.getId() != seekBar.getId()) )
{
return false;
}
// The View is either a child of the seekBar or is the seekBar itself,
// so we pass the event along to the seekBar and return true, signifying
// that the event has been consumed.
seekBar.onTouchEvent(event);
return true;
}
}
尝试一下,看看它是否有效;您可能需要为if语句创建一个更健壮的条件。