den*_*pyr 2 android webview android-webview
有时,当我加载页面时(没有静态内容,即时构建)我看到字体太小了1.如果我重装,我会看到它2.我来回走看看吧.然后......小.不是特定页面,不是特定时间.甚至没有特定版本:我在ICS设备上部署,没问题,然后改变一些东西(比如字体大小),这就是问题所在.对于8和10个仿真器的部署也是如此.
我的观点很简单:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webviewArticle"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="12dp" >
</WebView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
HTML构造(内容参数格式为html)
String toShow = new StringBuffer()
.append("<html>")
.append("<head>")
.append("<style type='text/css'>body{ font-size: large; color: #FFFFFF; background-color: #000000;}</style>")
.append("</head>")
.append(String.format(
"<body><h1>%s</h1><div><img src='%s' alt='%s' style='width:100%%; height:auto' /></div><div style='background-color:#000000;'>%s</div><div><h3>%s</h3></div></body>",
article.getTitle(),
article.getImageLink().toString(),
article.getTitle(),
article.getContent().replace("%", "%25"), //html
article.getAuthor()))
.append("</html>")
.toString();
mBrowser.getSettings().setBuiltInZoomControls(true);
mBrowser.setInitialScale(1);
CompatibilityUtils.setLoadWithOverviewMode(mBrowser, true); //set based on android version
mBrowser.getSettings().setUseWideViewPort(true);
mBrowser.loadDataWithBaseURL("fake://in/order/to/refresh", toShow, "text/html", "utf-8",null);
Run Code Online (Sandbox Code Playgroud)
任何提示?
附加说明12/09/25:如图所示,WebView认为可用空间是屏幕的一半,并相应地放置文本.这很奇怪.什么是最奇怪的是,它认为文本(图像上方的标题和下面的div)而不是图像!
WebSettings settings= webView.getSettings();
Run Code Online (Sandbox Code Playgroud)
这个
settings.setTextSize(WebSettings.TextSize.SMALLEST);
Run Code Online (Sandbox Code Playgroud)
要么
settings.setDefaultFontSize(10);//Larger number means larger font size
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9254 次 |
| 最近记录: |