Rolling compatibility of Android WebView and Scrollview and method of blank processing

This article introduces the rolling compatibility and white space processing of WebView and Scrollview, which are shared with you as follows:

background

During development, we often encounter the use of web pages to display graphic content, and we often encounter the situation that webviews are nested in Scrollview, which starts to hurt people! "Why, the web page loaded by my WebView only displays a little bit, and the others are not displayed?" "when I refresh the page again, why does the WebView leave blank? "----------------- God, can't it be good?!

In order to solve the problem of egg pain in the project, many methods have been tried. On the Internet, it is said that unreasonable overflow is used in the web page. Indeed, it has been proved that the use of unreasonable overflow will only display a small height in the WebView nested in the Scrollview after the web page is loaded. That experience is quite embarrassing. Rational use of overflow can solve this problem, but how to deal with WebView blank? Let's talk about how to place WebView in XML layout and set its properties.

Step by step and practice basic skills first

WebView in XML is nested in Scrollview:

The height of WebView should be set to wrap_ Content. If necessary, set this attribute of the first child container of Scrollview:

Identify problems and how they are caused

We use WebView to load the web page. The web page may require us to refresh the web page or load new links when we need it. At this time, the problem appears. Due to the length of the content loaded on the web page or the delay of Ajax request, the WebView can only continuously increase its height. When the web page height becomes smaller, the WebView height can not be adaptive, so we can only do something manually!

It is urgent to solve the problem and leave it blank

1. Overload webviewclient and override onpagefinished method.

2. JS injection, initialize the injection method

The web page also needs to call the JS injection method after data loading is completed.

Remarks and explanation:

① . document. Body. Getboundingclientrect(). Bottom: the distance between the lower edge of the page and the upper edge of the page

② Implementation of the. Viewutil. Setviewlayoutparams... Method

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>