WebView wrap-content

前端 未结 10 2445
我寻月下人不归
我寻月下人不归 2020-12-13 02:26

Is it possible to load a URL in a WebView and resize it to fit the screen? I mean I want to make the WebPage small so that the user doesn\'t need to scroll. Is this possible

10条回答
  •  不思量自难忘°
    2020-12-13 02:43

    I was able to contain the entire page in my view by doing the following. First set the width and height to wrap_content. Then setting the initial scale to one like this:

    WebView webview = (WebView) currentActivity.findView(R.layout.web_view, R.id.webview);
    webview.setInitialScale(1);
    

    I found that I could get this to keep the width to the minimum necessary to display a readable font and then scroll along the y coordinate every time by doing the following. First set both the height and width to wrap_content. Then set the zoom density to far in your code like this:

    WebView webview = (WebView) currentActivity.findView(R.layout.web_view, R.id.webview);
    webview.getSettings().setDefaultZoom(ZoomDensity.FAR);
    

    This is probably the better solution most of the time. Consider how small the font would be if you displayed the following web page in its entirety:

提交回复
热议问题