简体   繁体   English

Android WebView iFrame字体缩放

[英]Android WebView iFrame font scaling

I have an app that essentially just loads a website to display that information. 我有一个应用程序,基本上只是加载一个网站来显示该信息。 Within the website I have an iframe that loads an events calendar. 在网站中我有一个加载事件日历的iframe。

Viewing the website (via Chrome) on a computer, the events calendar looks exactly the way it should (yes I know the font is ridiculously small). 在计算机上查看网站(通过Chrome),事件日历看起来应该是它应该的样子(是的,我知道字体非常小)。

Viewing the site on a FireTV Stick via the Android app, the font size within the iFrame (events calendar) scales up. 通过Android应用程序在FireTV Stick上查看网站,iFrame(事件日历)中的字体大小可以扩展。

I have noticed that with the FireTV, when the resolution is 1920x1080 the actual display resolution is 960x540 (which scaling the browsing down to will cause that same effect) @see Screen Size and Resolution 我注意到使用FireTV时,当分辨率为1920x1080 ,实际显示分辨率为960x540 (将浏览缩小到相同的效果)@see 屏幕尺寸和分辨率

Image in Chrome (displays correctly) Chrome中的图片(正确显示) Chrome中的图片(正确显示) FireTV WebView (incorrect) FireTV WebView(不正确) FireTV(不正确) I have also read up on Font-Boosting which is initially what I thought the issue was, but I have eliminated that as none of the techniques to "disable" it worked ( html * {max-height: 99999999px} , etc...) 我也读过Font-Boosting ,这最初是我认为的问题,但我已经消除了,因为没有“禁用”它的工作( html * {max-height: 99999999px}等等... )

I feel as though the issue lies in the way I am calling the WebView in the Android app and the settings that are being applied. 我觉得好像问题在于我在Android应用程序中调用WebView以及正在应用的设置。 I'm almost certain that I am missing something there that would fix this issue. 我几乎可以肯定我错过了那些可以解决这个问题的东西。 Here is what I have for the WebView settings: 以下是我对WebView设置的看法:

mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();

webSettings.setJavaScriptEnabled(true);
webSettings.setMediaPlaybackRequiresUserGesture(false);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true);
webSettings.setDefaultFontSize(12);
mWebView.setInitialScale(1);

EDIT 1: Okay, I figured out it is not only the iFrame that is scaling up, but it is all the content on the FireTV (this is apparently a feature). 编辑1:好的,我发现不仅iFrame正在扩大规模,而且它是FireTV上的所有内容(这显然是一个功能)。 Their display resolution (dp) is 960x540. 它们的显示分辨率(dp)为960x540。 It appears that there is no way of making things 1920x1080, but when I display the iframe via Rise Vision's "My Rise Player" app, everything appears as normal. 似乎没有办法制作1920x1080的东西,但是当我通过Rise Vision的“My Rise Player”应用程序显示iframe时,一切看起来都很正常。

How did they find a way to make things appear 1920x1080 on a FireTV? 他们是如何找到一种方法在FireTV上显示1920x1080的内容?

If anyone in Rise Vision's dev team would care to comment and point me in the right direction, I would greatly appreciate it! 如果Rise Vision的开发团队中的任何人都愿意评论并指出我正确的方向,我将非常感激!

The solution to this was rather simple. 对此的解决方案相当简单。 I just needed to set these values to 100 我只需要将这些值设置为100

mWebView.getSettings.setTextZoom(100);
mWebView.setInitialScale(100);

Thanks to @altskop for getting me in the right direction 感谢@altskop让我朝着正确的方向前进

For those who are wondering the rest of the code, here you go: 对于那些想知道其余代码的人,请转到:

WebView mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();

mWebView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        Log.d(TAG, "Finished Loading.");
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
});

webSettings.setJavaScriptEnabled(true);
webSettings.setMediaPlaybackRequiresUserGesture(false);
webSettings.setTextZoom(100);

mWebView.setInitialScale(100);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.loadUrl("http://your.url.com");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM