[英]Android Webview has extra white space at the bottom
I'm using the following method with HTML to load a local image into webview 我正在使用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);
}
And the XML part 和XML部分
<WebView
android:id="@+id/my_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
But using this method I'm getting an extra white space at the bottom after scrolling down if the phone's orientation is portrait. 但是使用这种方法,如果手机的方向是纵向,我会在向下滚动后在底部获得额外的空白区域。
The image's width 1,5 times bigger than it's height, so as I understand WebView
loads the image and by increasing height makes the content square(width and height equal) but increasing it just by adding an extra white space to the height. 图像的宽度比它的高度大1.5倍,因此我理解
WebView
加载图像并通过增加高度使内容为正方形(宽度和高度相等),但仅通过向高度添加额外的空白区域来增加它。
But if phone's orientation is landscape, it works without any problem, without adding any white space. 但是,如果手机的方向是横向的,它可以毫无问题地工作,而不会增加任何空白区域。
So please help me to understand what is the actual reason of the problem and how to solve it. 所以请帮助我了解问题的实际原因以及解决方法。 Thank you in advance.
先感谢您。
Try this. 尝试这个。
<WebView
android:id="@+id/web_view"
android:scrollbarStyle = "insideOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
make your WebView
height wrap_content
: 使您的
WebView
高度wrap_content
:
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
It works for me even in portrait mode :) 即使在肖像模式下它也适合我:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.