Issue
I have a webView like this
<?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>
That I want to load a HTML-String. I also want the content to be zoomable.
It works well on some devices, an strange on others. It seems that some devices layout the content again, after zooming. This causes linebreaks in the content (on Samsung S4, Huawei Ascend Mate 7)
The zooming works as expected on Nexus 5x, Nexus 7:
When I zoom websites (in Chrome, or other browsers) it works on all devices the same way (like in the second screenshot, no linebreaks). So I must be doing something wrong. But what?
Here is how I set the content:
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", "");
And the HTML-String in a better shape:
<!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>
Solution
I found the cause of this problem.
Changing android:layout_height="wrap_content"
to "match_parent"
solves this (event if it does not change anything in the layout). I still have no clue, why exactly this happens, but at least it works now.
Answered By - AlbAtNf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.