1 year ago
#387084
Iraklis Inguana
WebView crops stream after resize
I have a webView inside a collapsingToolBarLayout. I use the OnOffsetChangedListener callback provided by the AppBarLayout to adjust the size of the webView (i insert layoutParams inside webView) dynamically as the user scrolls down/up. What I observe is that the stream crops itself once I start decreasing the webView size and it shows only a part of the stream. Once I scroll up the stream shows fine.
I have included in my webview setup some solutions i have found on other questions like:
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
but they didn't have an effect.
I want to point out that this callback (OnOffsetChangedListener) is being called repeatedly even when the user doesn't scroll (because of UI updates), so my webview setup is being called multiple times. I am not sure why this is happening, is there any way to achieve this?
INSIDE onOffsetChangedListener:
My webView setUp method:
var settings: WebSettings? = webView?.getSettings()
//WebSettings settings = streamHolder.getSettings();
settings?.setJavaScriptEnabled(true)
settings?.setAppCacheEnabled(true)
settings?.setLoadWithOverviewMode(true)
settings?.setAllowFileAccess(true)
settings?.useWideViewPort = true
settings?.setAllowUniversalAccessFromFileURLs(true)
settings?.setDomStorageEnabled(true)
settings?.setDatabaseEnabled(true)
//settings?.setSupportZoom(true)
webView?.setWebViewClient(object: BaseWebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
//view?.zoomOut()
}
})
and inside load url method:
if (webView?.url.equals(url))
return
if (url != null) {
mWebViewStream?.loadUrl(url)
android
kotlin
webview
resize
android-webview
0 Answers
Your Answer