如何以编程方式滚动的Android的WebView [英] How to Programmatically Scroll Android WebView
问题描述
我试图以编程方式滚动的WebView在DOM树的特定元素的位置。但到目前为止,我还没有能够得到的WebView响应滚动请求。我试过使用 window.scrollTo(...)
调用JavaScript的,但的WebView没有响应。在Java方面,我已经打过电话了 WebView.flingScroll(...)
方法。的WebView会回应 flingScroll
,但我需要的是一个 scrollTo(...)
的能力。任何想法?
I'm trying to programmatically scroll a WebView to the location of a particular element in the DOM tree. But so far I haven't been able to get the WebView to respond to scroll requests. I've tried calling JavaScript that uses window.scrollTo(...)
, but the WebView doesn't respond. On the Java side, I've tried calling the WebView.flingScroll(...)
method. WebView will respond to flingScroll
, but what I need is a scrollTo(...)
capability. Any ideas?
推荐答案
我发现这个问题的一个更好的答案。事实证明,WebView功能确实有scrollTo(),getScrollX()和getScrollY()方法,如你所期望。他们有点隐藏在文档中,因为他们从View继承(通过AbsoluteLayout - >的ViewGroup - >查看)。这显然是一个更好的方式来操作比有些繁琐的JavaScript接口的WebView的滚动位置。
I've found a better answer to this issue. It turns out that WebView does have scrollTo(), getScrollX() and getScrollY() methods as you'd expect. They're a bit hidden in the documentation because they're inherited from View (via AbsoluteLayout -> ViewGroup -> View). This is obviously a better way to manipulate the WebView's scroll position than the somewhat cumbersome JavaScript interface.
这篇关于如何以编程方式滚动的Android的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!