我正在尝试将webview内容与屏幕相匹配,但它显示非常难看并显示不同的结果,请参阅下面的屏幕截图链接:
http://postimg.org/image/jy0g268p1/0294ca52/
http://postimg.org/image/603z8qhab/e06b655e/
请在下面找到我的代码:
WebSettings settings = webView.getSettings();
settings.setMinimumFontSize(30);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
webView.loadData(htmlContent, "text/html", "UTF-8");
webView.setInitialScale(1);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
请告知我应该做些什么来很好地适应内容? 真的很感激任何帮助。
答案 0 :(得分:14)
我想我已经找到了自己的解决方案,我把它放在了将来需要它的人身上。 我只是创建了一个方法来改变html的头部:
public static String changedHeaderHtml(String htmlText) {
String head = "<head><meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" /></head>";
String closedTag = "</body></html>";
String changeFontHtml = head + htmlText + closedTag;
return changeFontHtml;
}
我在webview中使用它如下:
public static void displayHtmlText(String htmlContent, String message,
WebView webView,
RelativeLayout videoLayout, LinearLayout standardLayout, LinearLayout webviewLayout){
WebSettings settings = webView.getSettings();
settings.setMinimumFontSize(18);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
webView.setWebChromeClient(new WebChromeClient());
String changeFontHtml = Util.changedHeaderHtml(htmlContent);
webView.loadDataWithBaseURL(null, changeFontHtml,
"text/html", "UTF-8", null);
webviewLayout.setVisibility(View.VISIBLE);
standardLayout.setVisibility(View.GONE);
videoLayout.setVisibility(View.GONE);
}
因此,我现在在webview中的内容适合设备并且可以很好地显示。
答案 1 :(得分:11)
这对我有用:
1.sometime you will get an error in selenium =
**Exception in thread "main" org.openqa.selenium.WebDriverException: Element is not
clickable at point (1019, 62.5). Other element would receive the click.**
which means the element you wanted to click is present in the DOM but yet not have
fixed position inside the DOM so your operation (click) will be performed at some other
location.