Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured it out. I had to set the initial scale of the webview, and that allows me to view the WebView in 720p even though the screen resolution is 1080p.</p> <p>This is the code I used:</p> <pre><code>boolean _bReloaded = false; boolean _bLoaded = false; int _nWebScale = 100; DisplayMetrics displaymetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int nScreenHeight = displaymetrics.heightPixels; if(nScreenHeight &gt;= 1000){ _nWebScale = (int) Math.round((nScreenHeight/720.0) * 100.0); _bReloaded = false; mWebView.setVisibility(View.INVISIBLE); } mWebView.setInitialScale(_nWebScale); </code></pre> <p>But I wasn't done there. </p> <p>At this point, the webView is displayed in the proper resolution; however, there is a noticeable resizing of the webview window when the webView loads. This is why in the above code I hide the webview. Another problem is that in my particular case, my HTML wasn't listening to a window resize event and so it didn't readjust its UI after the webview was noticeably seen changing size. To fix this I could change my HTML and have it react to a JavaScript window resize event, or I could do what I ultimately went with - reloading the webview after it loads with the incorrect sized UI. With this solution I didn't have to react to a window resize event:</p> <pre><code>mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { if (progress == 100) { if(_nWebScale != 100 &amp;&amp; (mWebView.getVisibility() != View.VISIBLE) &amp;&amp; !_bReloaded){ _bReloaded = true; mWebView.reload(); } else { _bLoaded = true; displayLoadingSpinner(false); mWebView.setVisibility(View.VISIBLE); } } else if (mProgressBar.getVisibility() != View.VISIBLE) { displayLoadingSpinner(true); _bLoaded = false; } } }); </code></pre> <p>Another piece of info that isn't directly related to the original question, but may be useful is the following. Within my code, I had to resize and reposition a VideoView based on parameters that were sent from the webview. But because the webview may be in a different resolution than the actual display resolution, I had to adjust the parameters to make them in terms of the screen resolution.</p> <p>For example:</p> <pre><code>//this parameter is equal to the width of the webview screen: 720 nHeightFromWebView; //This is the x position of where the VideoView should be placed. nXFromWebView; float nScale = (float)_nWebScale/100; int nAdjustedHeight = (int) Math.round(((float)nHeightFromWebView * nScale)); //The adjusted height computes to 1080 - the actual resolution of the screen int nNewX = (int)Math.round((float)nXFromWebView * nScale); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload