I'm trying to apply the extension expansion function in Webview based on its content height, but I always get the wrong value. Here is my code
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) {
and then in the fragment I tried to get the height of the content
webView.setWebChromeClient(new WebChromeClient(){ @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if(newProgress==100) { new Handler().postDelayed(new Runnable() { @Override public void run() { webView.setChangeContentListener(new WebViewContentHeight() { @Override public void updateContentHeight(int height) { if(height>0 && getActivity()!=null) { System.out.println("the height2 is" + height + " " + Utils.convertPixelsToDp(height, getActivity())); final int text_height = height;
but my problem is that I always get the wrong result Thanks
android html webview
Antwan
source share