如何在Android上将视图的onClick事件传递给其父级? [英] How to pass a view's onClick event to its parent on Android?
问题描述
我在布局中有一个TextView,其背景是选择器.然后,将TextView的文本设置为从HTML跨接". 然后,我使用LinkMovementMethod设置TextView.
I have a TextView in a layout whos background is a Selector. And the TextView's text is set to Spanned from HTML. Then I set the TextView with the LinkMovementMethod.
现在,当我点击TextView时,click事件不会发送到其父级布局以触发选择器.
Now when I tap on the TextView, the click event is not sent to its parent layout to trigger the selector.
应如何解决?
推荐答案
我认为您需要使用这些方法之一才能在将事件发送到适当的组件之前对其进行拦截:
I think you need to use one of those methods in order to be able to intercept the event before it gets sent to the appropriate components:
Activity.dispatchTouchEvent(MotionEvent)
-这使您的活动"可以在所有触摸事件被分派到窗口之前对其进行拦截.
Activity.dispatchTouchEvent(MotionEvent)
- This allows your Activity to intercept all touch events before they are dispatched to the window.
ViewGroup.onInterceptTouchEvent(MotionEvent)
-这允许ViewGroup在将事件调度到子View时监视它们.
ViewGroup.onInterceptTouchEvent(MotionEvent)
- This allows a ViewGroup to watch events as they are dispatched to child Views.
ViewParent.requestDisallowInterceptTouchEvent(boolean)
-在父视图上调用此方法,以指示它不应使用onInterceptTouchEvent(MotionEvent)拦截触摸事件.
ViewParent.requestDisallowInterceptTouchEvent(boolean)
- Call this upon a parent View to indicate that it should not intercept touch events with onInterceptTouchEvent(MotionEvent).
更多信息此处.
希望有帮助.
这篇关于如何在Android上将视图的onClick事件传递给其父级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!