ときどき、自分のページ (動的に構築された静的コンテンツなし) をロードすると、フォント サイズが小さすぎることがわかります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>
HTML 構造 (content パラメータは 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);
ヒントはありますか?
追加説明 12/09/25: 画像が示すように、WebView は使用可能なスペースが画面の半分であると考え、それに応じてテキストを配置します。これは奇妙です。最も奇妙なのは、画像ではなくテキスト (画像の上のヘッダーと下の div) に対してそう考えていることです!!!