美文网首页
webView 监听内容滑动进度

webView 监听内容滑动进度

作者: 菜鸟何时起飞 | 来源:发表于2020-11-20 10:44 被阅读0次
    public class CusWebView extends WebView {
        public CusWebView(@NonNull Context context) {
            super(context);
        }
    
        public CusWebView(@NonNull Context context, @Nullable AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CusWebView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        @Override
        protected void onScrollChanged(int l, int t, int oldl, int oldt) {
            super.onScrollChanged(l, t, oldl, oldt);
            // webview的高度
            float webcontent = getContentHeight() * getScale();
            
            /*view的高度*/
            float height = getHeight();
            /*内容滑动百分比*/
            int percent = (int) (t/ (webcontent - height)*100);
    
        }
    
    }
    

    相关文章

      网友评论

          本文标题:webView 监听内容滑动进度

          本文链接:https://www.haomeiwen.com/subject/qlkdiktx.html