在做布局文件时,经常会有布局组件压在其它组件上面,这样点击上面布局没有控件的部分就会点中下面布局的控件。

如何拦截事件不让事件传递到下一层呢?

布局组件onTouchEvent() 用于处理事件,返回值决定当前控件是否消费(consume)了这个事件。

返回值为true时不在传递给子控件。

 View conentView = (View)ctx.findViewById(R.id.mylayoutid);
        conentView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
            

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2021-08-19
  • 2022-12-23
猜你喜欢
  • 2021-09-03
  • 2022-12-23
  • 2021-06-23
  • 2021-04-24
  • 2021-08-14
  • 2021-12-08
相关资源
相似解决方案