Android Webview的底部有额外的空白 [英] Android Webview has extra white space at the bottom

查看:1281
本文介绍了Android Webview的底部有额外的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将以下方法与HTML结合使用,以将本地图像加载到Webview中

I'm using the following method with HTML to load a local image into 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"/>     

但是使用这种方法,如果手机的方向是纵向,则向下滚动后在底部会有一个额外的空白.

But using this method I'm getting an extra white space at the bottom after scrolling down if the phone's orientation is portrait.

图像的宽度是高度的1.5倍,据我了解,WebView加载图像,并通过增加高度使内容变为正方形(宽度和高度相等),但只是通过向其添加额外的空白来增加它高度.

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.

但是,如果手机的方向为横向,则可以正常工作,而不会添加任何空白.

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.

推荐答案

使您的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 :)

这篇关于Android Webview的底部有额外的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆