I WebView data in WebView and expect that the picture as the text will occupy the entire width of the screen. But on the sides, that the text, that the picture remains free space of approximately 8dp .
In the activit class:
// Set content String content = bodyContent; //сюда передаю тело документа с разметкой. Display display = getWindowManager().getDefaultDisplay(); int displayWidth = display.getWidth(); View webLayout = getLayoutInflater().inflate(R.layout.partial_article_web, null); web = webLayout.findViewById(R.id.content); WebSettings settings = web.getSettings(); settings.setTextZoom(storage.getTextZoom()); settings.setSupportZoom(false); settings.setJavaScriptEnabled(true); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); web.addJavascriptInterface(this, "android"); web.loadDataWithBaseURL("", asHtmlPage(content, "text/html", "utf-8", null); And here is how I form the data for loading in WebView :
private String asHtmlPage(String body) { String style = "<style>" + "body { font-family: 'sans-serif-light', sans-serif; }" + "img { display: inline; height: auto; max-width: 100%; } " + "</style>"; String meta = "<meta name='viewport' content='width=device-width, initial-scale=1'>"; return "<html><head>" + style + meta + "</head><body>" + body + "</body></html>"; } WebView Markup:
<WebView android:id="@+id/content" style="?android:textAppearanceMedium" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="16dp" android:paddingBottom="16dp" android:scrollbars="none" /> I tried:
comment
settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true);- moved the
metablock with<head>in<body> Changed:
<meta name='viewport' content='width=" + displayWidth + " , initial-scale=1'>";In style changed
max-width: 100%;onmax-width: " + displayWidth + ";
The content that I load does not have any indents or borders on the sides.
Help me figure out where this unexpected Padding comes from.
UPD: As noted by @Timur Mukhortov, corrected @dimen/activity_horizontal_margin in the xml markup of WebView at 16dp .