2016-05-30 65 views
1

多余的空白我使用的HTML以下方法给本地图像加载到的WebView的Android网页视图在底部

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加载图像,并通过增加高度使内容方(宽度和高度相等),但增加它只是通过增加一个额外的空白时代高度。

但是,如果手机的方向是风景,它没有任何问题,没有增加任何空白的作品。

所以请帮我理解问题的实际原因以及如何解决问题。 预先感谢您。

回答

0

试试这个。

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

没有,它没有影响 – JHets15

+0

,因为它不是关于scrollbarStyle,但它是关于WebView的内容大小 – JHets15

0

让你WebView高度wrap_content

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

它为我即使在纵向模式下:)

+0

不是,它不是关于视图的高度,而是关于内容的高度。 – JHets15

+0

你是什么意思?在你的问题中加入一些截图 –