什麼工作對我來說是這樣的:我讀的是,爲了適應屏幕寬度,你應該添加到您的HTML或XML領域內:
width="100%"
所以我做的是,而不是縮放和縮放圖像,我得到的XML,把它放在一個StringBuilder,找到src =「https://blablabla.com/image.png」是在字段並在「src」子字符串之前插入「width =」100%「」,然後y使用StringBuilder設置我的webView,mi代碼如下:
public void setWebViewWithImageFit(String content){
// content is the content of the HTML or XML.
String stringToAdd = "width=\"100%\" ";
// Create a StringBuilder to insert string in the middle of content.
StringBuilder sb = new StringBuilder(content);
int i = 0;
int cont = 0;
// Check for the "src" substring, if it exists, take the index where
// it appears and insert the stringToAdd there, then increment a counter
// because the string gets altered and you should sum the length of the inserted substring
while(i != -1){
i = content.indexOf("src", i + 1);
if(i != -1) sb.insert(i + (cont * stringToAdd.length()), stringToAdd);
++cont;
}
// Set the webView with the StringBuilder: sb.toString()
WebView detailWebView = (WebView) findViewById(R.id.web_view);
detailWebView.loadDataWithBaseURL(null, sb.toString(), "text/html", "utf-8", null);
}
希望這會有所幫助,我花了幾個小時才弄清楚如何解決這個問題。
它最好不要使用LayoutAlgortihm.SINGLE_COLUMN,因爲它已經過時,現在已經過時。 –