How to Programmatically Scroll Android WebView

前端 未结 5 2042
眼角桃花
眼角桃花 2020-11-29 23:18

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 s

5条回答
  •  半阙折子戏
    2020-11-29 23:55

    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.

提交回复
热议问题