2011-08-23 244 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