Java 在Android WebView上安装图像
我正在使用WebView,我想在其中显示一个图像 我想在webview中调整图像。(图像变得太大,所以我必须水平滚动) 我显示这样的图像(如果有必要):Java 在Android WebView上安装图像,java,android,html,image,webview,Java,Android,Html,Image,Webview,我正在使用WebView,我想在其中显示一个图像 我想在webview中调整图像。(图像变得太大,所以我必须水平滚动) 我显示这样的图像(如果有必要): 我所尝试的: WebView content = (WebView) findViewById(R.id.webView1); content.loadDataWithBaseURL(null, "<style>img{display: inline;height: auto;max-width: 100%;} </sty
我所尝试的:
WebView content = (WebView) findViewById(R.id.webView1);
content.loadDataWithBaseURL(null, "<style>img{display: inline;height: auto;max-width: 100%;}
</style>" + CONTENT, "text/html", "UTF-8", null);
它可以工作,但不好,因为它缩小了网络视图,文本变得不可读。
还有其他方法吗?如果您使用此代码,它将允许您在webview中容纳所有图像
String imageUrl = "<Put here the image>";
String html = "<html><head>" +
"<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">"+
"<style>\n" +
"html,body{ margin:auto;}"+
"#image{\n" +
" width: 100vw;\n" +
" height: 100vh;\n" +
"}\n" +
"</style></head>\n" +
"<body>\n" +
"<img id=\"image\" src=\""+imageUrl+"\" alt =\"no image\">\n" +
"</body></html>";
webView.loadDataWithBaseURL(null,html,"text/html", "UTF-8", null);
String imageUrl=”“;
字符串html=“”+
""+
“\n”+
html,正文{margin:auto;}+
“#图像{\n”+
“宽度:100vw;\n”+
“高度:100vh;\n”+
“}\n”+
“\n”+
“\n”+
“\n”+
"";
loadDataWithBaseURL(null,html,“text/html”,“UTF-8”,null);
String imageUrl = "<Put here the image>";
String html = "<html><head>" +
"<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">"+
"<style>\n" +
"html,body{ margin:auto;}"+
"#image{\n" +
" width: 100vw;\n" +
" height: 100vh;\n" +
"}\n" +
"</style></head>\n" +
"<body>\n" +
"<img id=\"image\" src=\""+imageUrl+"\" alt =\"no image\">\n" +
"</body></html>";
webView.loadDataWithBaseURL(null,html,"text/html", "UTF-8", null);