【问题标题】:How to get last scroll position a of WebView如何获取 WebView 的最后滚动位置
【发布时间】: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


【解决方案1】:

尝试使用这个方法 listView.getFirstVisiblePosition();如果你想要 listView 内容滚动多远。

【讨论】:

  • 这是一个 WebView :/
  • webView 总是为 getScrollY() 返回 0 ...这就是问题所在:/
  • @Mehrad 你能找到解决这个问题的办法吗?
猜你喜欢
  • 2017-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-29
相关资源
最近更新 更多