相关疑难解决方法(0)

加载Android后获取WebView Content高度

我正在尝试在Webview上应用展开折叠功能基于其内容高度,但我总是得到错误的值这是我的代码

public class MesuredHeightWebView extends WebView {
    public MesuredHeightWebView(Context context) {
        super(context);
    }

    public MesuredHeightWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MesuredHeightWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }



    @Override
    public void invalidate() {
        super.invalidate();

        if (getContentHeight() > 0) {
            // WebView has displayed some content and is scrollable.
            if(listener!=null)
                listener.updateContentHeight(getContentHeight());
        }
    }



    WebViewContentHeight listener;

    public void setChangeContentListener(WebViewContentHeight listener) {
        this.listener = listener;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在片段中我试图获得内容高度

 webView.setWebChromeClient(new WebChromeClient(){
        @Override
        public void onProgressChanged(WebView view, int newProgress) …
Run Code Online (Sandbox Code Playgroud)

html android webview

5
推荐指数
1
解决办法
5379
查看次数

标签 统计

android ×1

html ×1

webview ×1