如何获取webview的最后一个滚动位置

xxslljrj  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(314)

我在用 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;
}
l3zydbqr

l3zydbqr1#

尝试使用此方法listview.getfirstvisibleposition();如果您想知道listview内容的滚动距离。

相关问题