【发布时间】:2017-07-14 12:41:00
【问题描述】:
我正在使用WebView 来显示一个较长的静态帖子。所以我需要保存用户正在阅读的最后一个位置并稍后恢复该位置。
我该怎么做?
我试图获取 WebView 的滚动位置百分比,但 getScrollY() 返回 0
我重写了 WebView 的 onScrollChange() 方法,但是当我滚动页面时,这似乎没有调用 onScrollChange() 方法。
我的 HTML 示例代码:
<html>
<head>
<style>
someStyle ... no position style here
}</style>
</head>
<body>
<div><html>
<head></head>
<body>
<table>
<tbody>
<tr>
<td>
<p align="left"><font size="1" color="#FF0000">[</font></p> <p align="left" style="line-height: 130%"><font>someText</font></p>
</tr>
</tbody>
</table>
</body>
</html>
</html>
我的获取百分比方法:
private float calculateProgression(WebView content) {
float positionTopView = content.getTop();
float contentHeight = content.getContentHeight();
float currentScrollPosition = content.getScrollY();
float percentWebview = (currentScrollPosition - positionTopView) / contentHeight;
return percentWebview;
}
【问题讨论】:
-
发帖前你检查过这个吗?
标签: java android html css webview