Android - 忽略父视图触摸子视图触摸

时间:2014-07-25 06:28:06

标签: android touch android-relativelayout

我有像

这样的布局
RelativeLayout_Parent
  -> RelativeLayout_Child

两个视图都有触摸事件。 但是当我触摸RelativeLayout_Child时,触发父亲的事件也会被触发。

如何忽略父视图触摸子视图触摸?

1 个答案:

答案 0 :(得分:4)

非常简单,在您的子视图上实现OnTouchListener,一旦收到Touch Event,就会返回true,这将确保触摸事件不会传播给其他人。

    child_view.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            // this will make sure event is not propagated to others, nesting same view area
            return true;
        }

    });
相关问题