android studio 如何根据设备屏幕的大小调整 webview 的大小

How to resize the webview According to the size of device Screen in android studio

我已经创建了一个带有 Web 视图的 android 工作室项目。 Web 视图包含响应式网站。我用 smart phone(nokia3) 测试了我的应用程序。但我不知道它如何与选项卡一起使用。因为我没有平板电脑。但我找到了一些解决方案,你能告诉我哪个是正确的吗?

甲:

mWebView.getSettings().setUseWideViewPort(true);  
mWebView.getSettings().setLoadWithOverviewMode(true);

乙:

WebSettings webSettings = appView.getSettings();
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);

两者是一样的。 两者在功能方面都是正确的。

您可以选择其中任何一个。

A. 正在修改webview的设置,直接从视图中引用

B. 它首先获取 WebSettings 对象,然后修改其状态。

您可以设置 Webview 的宽度和高度match_parent。但请确保如果设置了填充,则移除填充。