什么工作对我来说是这样的:我读的是,为了适应屏幕宽度,你应该添加到您的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);
}
希望这会有所帮助,我花了几个小时才弄清楚如何解决这个问题。