图像无法在Web视图中正确显示

时间:2014-03-28 16:20:37

标签: android-webview

我正在尝试将图片从rss Feed的html页面放到网页视图中。

当我加载图像时,它会放大并仅显示部分图像。 有些图像会随机发生。

但是当我尝试在模拟器中或在调试后加载它们时,它会正确显示所有图像(它们适合Web视图)。

如何修复它。

布局:

<com.philly.prosportsframework.view.ProgressWebView 
        android:id="@+id/photo" 
        android:layout_width="300dip" 
        android:layout_height="300dip"
        android:layout_below="@+id/divider"
        android:layout_centerHorizontal="true"      
        android:layout_marginTop="10dip"
        android:layout_marginBottom="10dip"/>

一块WebviewCode:

    int imageScale = 100;
    viewHolder.mPhoto.getSettings().setJavaScriptEnabled(true);
    viewHolder.mPhoto.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
    viewHolder.mPhoto.setBackgroundColor(Color.parseColor("#00000000"));
    viewHolder.mPhoto.setInitialScale(imageScale);  

1 个答案:

答案 0 :(得分:0)

以下答案帮助我解决了这个问题:

"String data="<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="+width+", initial-scale=0.65 \" /></head>";
data=data+"<body><center><img width=\""+width+"\" src=\""+url+"\" /></center></body></html>";
webView.loadData(data, "text/html", null);"

我将宽度设置为300以适应我的布局。

它在链接中: Android WebView, Scaling Image to fit the screen

相关问题