首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android中的Webview图像适配屏幕

Android中的Webview图像适配屏幕
EN

Stack Overflow用户
提问于 2013-07-10 12:06:09
回答 3查看 6.3K关注 0票数 0

我将a .jpg加载到WebView中。我的问题是我找到了这个:Android WebView, Scaling Image to fit the screen

对我来说不管用。

这里是我的代码:

代码语言:javascript
复制
Display display = getWindowManager().getDefaultDisplay();
    int width= display.getWidth();

    Toast.makeText(getApplicationContext(), ""+width, Toast.LENGTH_LONG).show();


    String html = "<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="+width+", initial-scale=0.65 \" /></head>";
    html+= "<body><img width=\""+width+"\"<img src=\""+"image.jpg"+"\" /></body></html>";

aboutText.loadDataWithBaseURL("file:///android_res/drawable/", html, "text/html","UTF-8" , null);
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-07-10 12:07:53

您是html图像标记错误,请检查下面的代码:

代码语言:javascript
复制
Display display = getWindowManager().getDefaultDisplay();
int width= display.getWidth();

Toast.makeText(getApplicationContext(), ""+width, Toast.LENGTH_LONG).show();


String html = "<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="+width+", initial-scale=0.65 \" /></head>";
   html+= "<body><img width=\""+width+"\" src=\""+"image.jpg"+"\" /></body></html>";

aboutText.loadDataWithBaseURL("file:///android_res/drawable/", html, "text/html","UTF-8" , null);

html字符串格式错误的图像标记如下代码所示:

代码语言:javascript
复制
String html = "<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="+width+", initial-scale=0.65 \" /></head>";
html+= "<body><img width=\""+width+"\"<img src=\""+"image.jpg"+"\" /></body></html>";

格式化我的代码:

代码语言:javascript
复制
String html = "<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="+width+", initial-scale=0.65 \" /></head>";
html+= "<body><img width=\""+width+"\" src=\""+"image.jpg"+"\" /></body></html>";
票数 2
EN

Stack Overflow用户

发布于 2013-12-03 05:22:28

这不适合我,因为我有高分辨率的手机。

试试这个,它对我有用,webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

票数 5
EN

Stack Overflow用户

发布于 2015-03-24 04:14:21

在将HTML加载到web视图之前,可以对img标记进行样式设置。请参阅下面的代码

代码语言:javascript
复制
WebView content = (WebView) findViewById(R.id.webView1);
String head = "<head> <style>img{display: inline;height: auto;max-width:   100%;}</style> <style>body {font-family: 'Roboto';  }</style></head>";

content.loadDataWithBaseURL(null, head + post.getContent(), "text/html", "UTF-8", null);
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17570238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档