Android Webview has extra white space at the bottom

為{幸葍}努か 提交于 2020-01-16 05:30:09

问题


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);
   }

And the XML part

  <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.

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.


回答1:


make your WebView height 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 :)




回答2:


Try this.

 <WebView
        android:id="@+id/web_view"
        android:scrollbarStyle = "insideOverlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


来源:https://stackoverflow.com/questions/37521832/android-webview-has-extra-white-space-at-the-bottom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!