1.高度需要動態(tài)添加,我這邊是加載html字符串
meta:為了讓字體和div寬度適應(yīng)手機
ResizeImages:為了圖片自適應(yīng)屏幕寬度,根據(jù)需要調(diào)整骇两,這邊是整體圖片都適應(yīng)了朝群,沒判斷超出或者小于
onNavigationStateChange:通過WebView的方法,動態(tài)加載高度
<View style={{ height: this.state.webViewHeight, width: ScreenWidth }}>
<WebView
source={{html:
`<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<body>
${this.state.detailInfo.DetailHtml}
<script>
function ResizeImages(){
var myimg;
for(i=0;i <document.images.length;i++){
myimg = document.images[i];
myimg.width = ${ScreenWidth - 20};
}
}
window.onload=function(){
ResizeImages()
window.location.hash = '#' + document.body.clientHeight;
document.title = document.body.clientHeight;
}
</script></body></html>`
}}
style={{flex:1}}
bounces={false}
scrollEnabled={false}
javaScriptEnabled={true}
automaticallyAdjustContentInsets={true}
contentInset={{top:0,left:0}}
onNavigationStateChange={(title) => {
console.log(title);
if (title.title != undefined) {
this.setState({
webViewHeight: (parseInt(title.title) + 20)
})
}
}}
/>
</View>