简体   繁体   English

LinearLayout上的Android onTouchListener

[英]Android onTouchListener on LinearLayout

I have a linear layout with few child components in it. 我有一个线性布局,其中包含很少的子组件。 I have onTouchListener on the linearlayout. 我在linearlayout上有onTouchListener。 I want onTouch event to trigger when I touch child components of the linear layout too. 我想在触摸线性布局的子组件时触发onTouch事件。

You should be able to implement the onInterceptTouchEvent method in a custom subclass of LinearLayout to achieve that effect. 您应该能够在LinearLayout的自定义子类中实现onInterceptTouchEvent方法以实现该效果。 From the documentation: 从文档:

public boolean onInterceptTouchEvent (MotionEvent ev) public boolean onInterceptTouchEventMotionEvent ev)

Implement this method to intercept all touch screen motion events. 实现此方法以拦截所有触摸屏运动事件。 This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point. 这允许您在将事件发送给您的孩子时观察事件,并在任何时候获取当前手势的所有权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM