2011-08-23 220 views
1

我点击的API返回图像的URL。我想使用一个WebView,为它提供这个URL并让它显示图像。但是,我想让WebView成为静态的90dip x 90dip(图像是方形的)。图像大于9​​0px。有没有一种方法可以告诉WebView将图像大小调整到自己的尺寸?尺寸图像以适合WebView尺寸

回答

2

你试过了吗?它不起作用,如果不是,它会做什么呢?

我想你可以使用ImageView来显示没有问题的图像。您可以使用的方法类似这样从URL,然后你就可以设置为的ImageView与setImageDrawable(img);

/*********************************************************** 
* This method will return the image from a URL. 
* Note: This should be called from the UI thread. 
***********************************************************/ 
public Drawable getRemoteImage(final URL aURL) { 
    try { 
     final URLConnection conn = aURL.openConnection(); 
     conn.connect(); 
     final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); 
     final Drawable d = Drawable.createFromStream(bis, "src"); 
     bis.close(); 
     return d; 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return null; 
} 

的ImageView我知道你可以设置一个静态大小事实(90dip回报给你一个可绘制对象x 90dip),它会处理缩放图像,如果需要使其适合该尺寸,WebView可能会尝试使其可滚动或者其他,我不确定。

+0

是的,WebView添加滚动条。我会给这个镜头,1个时刻。 – Andrew

+0

这个工作适合你吗? –

+0

你在使用@prince有问题吗? – FoamyGuy