【发布时间】:2016-05-30 09:12:35
【问题描述】:
我正在使用下面的 HTML 方法将本地图像加载到 webview 中
void loadingImage(WebView mWebView){
mWebView.getSettings().setSupportZoom(false);
mWebView.getSettings().setDisplayZoomControls(false);
String mHead="<html><head><style type='text/css'>body{margin:auto auto;text-align:center;} img{width:100%25;} </style></head>";
String mBody = "<body> <img src='my_image.jpg'/> </body></html>";
mWebView.loadDataWithBaseURL("file:///android_res/drawable/", mHead + mBody, "text/html", "UTF-8", null);
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
}
还有 XML 部分
<WebView
android:id="@+id/my_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
但是使用这种方法,如果手机的方向是纵向的,我在向下滚动后底部会出现一个额外的空白。
图像的宽度是高度的 1.5 倍,据我所知 WebView 加载图像并通过增加高度使内容为正方形(宽度和高度相等),但仅通过添加额外的空白来增加它高度。
但如果手机的方向是横向的,它可以正常工作,不会添加任何空白。
所以请帮助我了解问题的实际原因以及解决方法。 提前谢谢你。
【问题讨论】:
标签: android html android-webview android-xml android-drawable