问题描述
我的布局中有一个 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 时,点击事件不会发送到其父布局以触发选择器.
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 在将所有触摸事件分派到窗口之前拦截它们.
Activity.dispatchTouchEvent(MotionEvent)
- This allows your Activity to intercept all touch events before they are dispatched to the window.
ViewGroup.onInterceptTouchEvent(MotionEvent)
- 这允许 ViewGroup 在事件被分派到子视图时观察它们.
ViewGroup.onInterceptTouchEvent(MotionEvent)
- This allows a ViewGroup to watch events as they are dispatched to child Views.
ViewParent.requestDisallowInterceptTouchEvent(boolean)
- 在父 View 上调用它以指示它不应使用 onInterceptTouchEvent(MotionEvent) 拦截触摸事件.
ViewParent.requestDisallowInterceptTouchEvent(boolean)
- Call this upon a parent View to indicate that it should not intercept touch events with onInterceptTouchEvent(MotionEvent).
更多信息这里.
希望对您有所帮助.
这篇关于如何将视图的 onClick 事件传递给 Android 上的父级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!