2015-06-01 41 views
0

我有一個網頁視圖設置爲:調整在WebView中的所有圖像與自動調整文字大小

WebView wv = (WebView) findViewById(R.id.display_post_activity_content); 
     wv.getSettings().setLoadWithOverviewMode(true); 
     wv.getSettings().setUseWideViewPort(true); 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
      wv.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); 
     } else { 
      wv.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); 
     } 
wv.loadDataWithBaseURL("", content, "text/html", "UTF-8", ""); 

content是靜態的HTML,一些內聯CSS。沒有JavaScript。 這是一個很好的文字環繞工作。它還調整較大的圖像以適合屏幕寬度。

然而,也有一些比設備寬度小內嵌圖像。文字環繞這些。

我希望它來調整所有圖像(哪怕是很小的)與寬度(保持寬高比)。使用WebView可以實現嗎? 我可以用Html.fromHtml()ImageGetter做到這一點,但WebView的性能會更好。

回答

0

好了,我解決了這個一個自己:

// Content to be rendered 
content = "<p>Some Html </p> with <img></img> tags"; 

// Set width and height 
content = content.replace("<img", "<img height=\"auto\" width=\"100%\" "); 

// Render 
wv.loadDataWithBaseURL("", content, "text/html", "UTF-8", ""); 

,瞧,全寬圖像與保存寬高比!