Android Webview - Empty white space at the bottom after scaling to the device width

ぐ巨炮叔叔 提交于 2019-12-19 10:19:28

问题


I am scaling my webview to fit the content to the width of the screen using the following code:

webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setBuiltInZoomControls(true);

This works but now I am getting an empty space at the bottom of the content. The size (in height) of the empty space is directly proportional to the magnitude of the zoom it is doing. So for smaller devices, the size is greater.

My feeling is that scroll bars size are not being recalculated after the zoom has taken effect. This assumption is due to the fact that when zooming-in and out by tapping on the screen, empty space goes away. Although this is working on Android 2.3 but not on 4.0.

My question how to force the scrollbars to recalculate after the zoom. Or is there any other solution.

Thanks.

P.S. Here is how I defined the webview in xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#FFFFFF" >

    <WebView
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/web_view"
                android:background="#AAFFFFFF"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

</LinearLayout>
</ScrollView>

回答1:


Why do you have a webview within a linearlayout within a scrollview, first of all? A WebView inherits from scrollView and implements it's own scrolling, so what is the other scrollview for? Essentially you will have a scroller within a scroller!!! Secondly I do see that you have "wrap_content" for your WebView' android:layout_height property.



来源:https://stackoverflow.com/questions/11086738/android-webview-empty-white-space-at-the-bottom-after-scaling-to-the-device-wi

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