简体   繁体   English

缩小Webview内容宽度以适合屏幕

[英]Shrink Webview Content width to fit the screen

Im trying to shrink the width content of my webview down to fit with my screen so i dont have to scroll side way anymore...i tried so many code but it still doesnt anyone have any idea how?? 我试图缩小我的webview的宽度内容以适合我的屏幕,所以我不必再横向滚动...我尝试了很多代码,但仍然没有人知道怎么做?

heres my code so far. 到目前为止,这是我的代码。

    postView = (WebView) findViewById(R.id.postView);
    postView.setScrollBarStyle(WebView.OVER_SCROLL_NEVER);
    postView.setInitialScale((int) .8);
    WebSettings settings = postView.getSettings();
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptEnabled(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);

Well you can define width of webview with screenwidth itself and add it to its param section. 好吧,您可以使用screenwidth本身定义webview的宽度并将其添加到其param部分。

int screenWidth = getWindowManager()
                .getDefaultDisplay().getWidth();
postView.setLayoutParams(new TableRow.LayoutParams(
                    screenWidth / 2, LayoutParams.MATCH_PARENT, 1f));
/*I have assumed your webview's parent is tablerow. You must define layout params with respect to its parent. like if postview parentview is linearlayout then new LinearLayout.LayoutParams() must be used*/

This must solve your problem. 这必须解决您的问题。

Hope, this helps. 希望这可以帮助。

Edit 编辑

Ok, now I get your problem. 好的,现在我明白了。 But I think in your case you should allow the user to get zoom in/out , so that user will get control for data he wants to view. 但我认为,在您的情况下,应允许用户放大/缩小,以便用户可以控制要查看的数据。

Add this statement 添加此语句

postView.getSettings().setBuiltInZoomControls(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM