我有一个显示 WebView
的 ListActivity
。
有一个菜单选项可以复制将调用 this 的文本在可见的 WebView 上。
除了一件事,一切正常。我无法在垂直方向上执行文本选择,因为 ListView
会为其自身的滚动消耗相应的 MotionEvent
。
我试过这个:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (webViewsInTextSelectionMode) {
bypassEventToWebViews(ev);
return true;
} else {
return super.dispatchTouchEvent(ev);
}
}
这会阻止滚动,但也会将未调整的 MotionEvent
坐标传递给 WebView
。
在这种情况下,有没有办法正确地阻止 ListView 滚动?
最佳答案
I've got a ListActivity that displays WebViews.
这不是一个好主意。 WebView
和 ListView
会竞争运动事件。在 Android 中很少建议将滚动内容放在滚动内容中,尤其是当它们可以沿相同方向滚动时(在本例中为向上和向下)。
There is a menu option to copy text that will call this on visible WebViews.
如果您指的是该问题的公认答案,那也不是一个好主意。我对其他答案持怀疑态度,但至少这不是一个坏主意表面上看。
Everything works except for one thing. I can't perform text selection in vertical direction as ListView consumes corresponding MotionEvents for it's own scrolling.
我的观点完全正确。
Is there a way to correctly prevent ListView from scrolling in this case?
我会专注于摆脱 WebViews
,将它们替换为 TextView
和 Html.fromHtml()
。或者,摆脱 ListView
,使用单个 WebView
来呈现您的合并内容。
关于android - 临时绕过ListView滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4626676/