webView 监听内容滑动进度

2020-11-20  本文已影响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);

    }

}
上一篇下一篇

猜你喜欢

热点阅读