我将a .jpg加载到WebView中。我的问题是我找到了这个:Android WebView, Scaling Image to fit the screen
对我来说不管用。
这里是我的代码:
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);发布于 2013-07-10 12:07:53
您是html图像标记错误,请检查下面的代码:
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字符串格式错误的图像标记如下代码所示:
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>";格式化我的代码:
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>";发布于 2013-12-03 05:22:28
这不适合我,因为我有高分辨率的手机。
试试这个,它对我有用,webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
发布于 2015-03-24 04:14:21
在将HTML加载到web视图之前,可以对img标记进行样式设置。请参阅下面的代码
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);https://stackoverflow.com/questions/17570238
复制相似问题