GetContentHeight () is not working properly

I am trying to get the height of webview content. it contains an html string. The problem is that getContentHeight () always returns the same value (392), no matter how long the html string is.

+4
source share
2 answers

This problem infuriated me. Let me assume: your content is not downloaded from the Internet or from the file system, and you are making a call to WebView.loadData() or WebView.loadDataWithBaseUrl() (where you specify null or an empty string in the latter case). Right?

If yes, then I probably have a solution for you that was inspired by this discussion : be sure to use the WebView.loadDataWithBaseUrl() method and provide baseUrl , which is not null , not an empty string and is different for different content data. According to the SDK documentation, baseUrl is only used to evaluate relative URLs within the data (for example, <img> tags that do not indicate the domain name in their src attribute), so if your data does not refer to external content, I think you can generate "virtual" urls (have not tried this).

It seems that the WebView looking at the URL and, if it does not change all subsequent calls to loadData... , will result in the same WebView height.

+3
source

I am having a problem with getContetHeight (). First, in the WebViewClient.OnPageFinish () callback, the height of the content has not yet been set, so I made this rather rude decision.

 Handler h; Runnable scroll_updater = new Runnable() { @Override public void run() { if(Thread.interrupted()) return; if(lyrics.getContentHeight() == 0) h.postDelayed(this, 100); setLyricsScroll(); } }; 
+2
source

Source: https://habr.com/ru/post/1336672/


All Articles