У меня есть WebView как этотWebview увеличение приводит к тому, содержание relayout на некоторых устройствах
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/MarginDefault">
<WebView
android:id="@+id/webView_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>
То, что я хочу, чтобы загрузить HTML-String. Я также хочу, чтобы контент был масштабируемым.
Он хорошо работает на некоторых устройствах, странных на других. Кажется, что некоторые устройства снова компонуют контент после масштабирования. Это вызывает разрывы строк в содержании (на Samsung S4, Huawei Ascend Mate 7)
Зумирование работает, как ожидалось на Nexus 5x, Nexus 7:
Когда я просигналить веб-сайтов (в Chrome, или других браузеров), он работает на всех устройствах одинаково (например, во втором скриншоте, без разломов). Поэтому я должен делать что-то неправильно. Но что?
Вот как я установил содержание:
webViewContent = (WebView) findViewById(R.id.webView_content);
webViewContent.getSettings().setBuiltInZoomControls(true);
webViewContent.getSettings().setDisplayZoomControls(false);
webViewContent.setInitialScale(100);
String content = "<!DOCTYPE html>\n" +
"<html>\n" +
"\t<head>\n" +
"\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" +
"\t\t<title>Test</title>\n" +
"\t\t<style type=\"text/css\">\t\t* {font-family: \"helvetica\"; font-size: 16;}\t\ta:link {color: " +
"#004A94;} \t\ta:visited {color: #004A94;} \t\ta:hover {color: #004A94;} \t\ta:active {color: " +
"#004A94}</style>\n" +
"\t\t</head>\n" +
"\t<body>\t\n" +
"\t\t<div style=\"padding-bottom: 2em;\">\n" +
"\t\t\t<h2>Just another test string which is quite long</h2>\n" +
"\t\t</div>\n" +
"\t</body>\n" +
"</html>";
webViewContent.loadDataWithBaseURL(ServerInformation.getBaseUrl(),
content
, "text/html", "UTF-8", "");
И в HTML-String в лучшей форме:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test</title>
<style type="text/css"> * {font-family: "helvetica"; font-size: 16;} a:link {color: #004A94;} a:visited {color: #004A94;} a:hover {color: #004A94;} a:active {color: #004A94}</style>
</head>
<body>
<div style="padding-bottom: 2em;">
<h2>Just another test string which is quite long</h2>
</div>
</body>
</html>