我有一个像
RelativeLayout_Parent
-> RelativeLayout_Child
两个视图都有触摸事件。但是当我触摸RelativeLayout_Child
时,parent的触摸事件也被触发。
如何在子视图触摸上忽略父视图触摸?
非常简单,在你的子视图上实现OnTouchListener,并且在接收到Touch Event时从child返回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;
}
});