机器人的WebView问题SINGLE_COLUMN模式 [英] Android webview issue with SINGLE_COLUMN mode

查看:213
本文介绍了机器人的WebView问题SINGLE_COLUMN模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前具有Android的的WebView 一个问题。 这是web视图这样当前已初始化:

  _post_WebView =(web视图)view.findViewById(R.id.post_webview);
_post_WebView.setBackgroundColor(Color.WHITE);
_post_WebView.setWebViewClient(新PostWebViewClient());
。_post_WebView.getSettings()setBuiltInZoomControls(真正的);
。_post_WebView.getSettings()setSupportZoom(真正的);
。_post_WebView.getSettings()setPluginState(PluginState.ON);
_post_WebView.getSettings()setJavaScriptEnabled(真)。
_post_WebView.getSettings()setRenderPriority(RenderPriority.HIGH)。
。_post_WebView.getSettings()setCacheMode(WebSettings.LOAD_DEFAULT);
_post_WebView.setWebChromeClient(新WebChromeClient(){});
。_post_WebView.getSettings()setUseWideViewPort(假);
。_post_WebView.getSettings()setLoadWithOverviewMode(真正的);
。_post_WebView.getSettings()setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
 

此的WebView用于显示从服务器检索到的HTML字符串。 (使用 loadData 法)。现在的问题是,在 SINGLE_COLUMN 模式下,图像和文字正确的宽度和高度,但嵌入YouTube视频大小,而在宽度调整,不得到调整大小的高度,因此表现出什么,但一个黑盒子。

LayoutAlgorithm.NORMAL 一切工作正常。 我怎样才能确保YouTube视频的 SINGLE_COLUMN 算法得到适当调整呢?

在YouTube视频的嵌入是这样的:

 < IFRAME的allowFullScreen =FRAMEBORDER =0高度=315宽度=420SRC =YOUTUBE_VIDEO_LINK>< / IFRAME>
 

解决方案

我终于去,并使用 loadDataWithBaseURL(空,htmlString,text / html的解决了这个问题,UTF-8,空)而不是 loadData(htmlString,text / html的,UTF-8),同时增加了100%最大宽度属性和汽车宽度高度属性使用CSS的内置页框:

  htmlString =< HTML>< HEAD><风格>的iframe {最大宽度:100%;宽度:自动;身高:自动;}< /风格> /身体GT;< / HTML>中< /头><身体GT;+ htmlString +<
 

这不是最干净的方法,这样做,但它的作品。

如果使用的布局算法这个方法应该也适用 NARROW_COLUMNS

I'm currently having a issue with the Android WebView. This webview is currently initialized like this:

_post_WebView = (WebView) view.findViewById(R.id.post_webview);
_post_WebView.setBackgroundColor(Color.WHITE);
_post_WebView.setWebViewClient(new PostWebViewClient());
_post_WebView.getSettings().setBuiltInZoomControls(true);
_post_WebView.getSettings().setSupportZoom(true); 
_post_WebView.getSettings().setPluginState(PluginState.ON);
_post_WebView.getSettings().setJavaScriptEnabled(true);
_post_WebView.getSettings().setRenderPriority(RenderPriority.HIGH);
_post_WebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
_post_WebView.setWebChromeClient(new WebChromeClient() {});
_post_WebView.getSettings().setUseWideViewPort(false);
_post_WebView.getSettings().setLoadWithOverviewMode(true);
_post_WebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

This webview is used to display a HTML string retrieved from a server. (Using the loadData method). Now the problem is the fact that in SINGLE_COLUMN mode, the images and text are resized properly in both width and height but the embedded youtube videos, while resized in width, don't get resized in height and therefore show nothing but a black box.

In LayoutAlgorithm.NORMAL everything works fine. How can I make sure the youtube videos get resized properly in the SINGLE_COLUMN algorithm too?

The Youtube video's are embedded like this:

<iframe allowfullscreen="" frameborder="0" height="315" width="420" src="YOUTUBE_VIDEO_LINK"></iframe>

解决方案

I finally went and solved it by using loadDataWithBaseURL(null, htmlString, "text/html", "utf-8", null) instead of loadData(htmlString,"text/html","utf-8") while adding a 100% max-width property and a auto width and height property to the iframes using CSS:

htmlString = "<html><head><style>iframe {max-width: 100%; width:auto; height: auto;}</style></head><body>"+htmlString+"</body></html>";

It's not the most clean way to do so, but it works.

This method should also work if used with the layout algorithm NARROW_COLUMNS.

这篇关于机器人的WebView问题SINGLE_COLUMN模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆