【问题标题】:Image doesn't fit correctly in web view图像在 Web 视图中不正确
【发布时间】:2014-03-28 16:20:37
【问题描述】:

我正在尝试将图片从 rss 提要的 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);  

【问题讨论】:

标签: android-webview


【解决方案1】:

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

"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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多