Android WebView平滑滚动到锚点

时间:2014-03-25 15:13:48

标签: android-webview anchor smooth-scrolling

我有一个带有许多锚点的WebView:

<a name='some_id'></a>

我可以使用以下内容跳转到锚点:

webView.loadUrl("javascript:(function() { " +
    "window.location.hash='#" + hash + "';" +
"})()");

但是有可能以某种方式顺利滚动到锚点吗?

1 个答案:

答案 0 :(得分:2)

不幸的是,这需要你的努力:

  1. 您需要determine the position of the anchor element on the page,而不是执行片段导航。您需要使用addJavaScriptInterface将其传达回Java端,不要忘记将您从JS获得的CSS像素转换为物理像素乘以webview.getScale()。< / p>

  2. 使用OverScroller将动画驱动到所需的滚动偏移。

相关问题