android - 如何在 Android 的 WebView 中加载 url 以正确查看?

标签 android android-emulator android-webview

我正在加载 http://www.google.com WebView 中的 url。 但是,即使我从设备/模拟器加载它,webview 的内容也不会根据设备尺寸进行调整。

Screen shot of the image

如果您看到,Google 页面未根据 WebVie 的尺寸正确设置。但是,如果我在具有相同尺寸的模拟器浏览器中打开相同的 url,那么它会通过缩放等方式正确加载。

如何在 Android 的 WebView 上正确加载 webview?

这是 WebView 布局的 XML
<WebView android:id="@+id/webView1" android:layout_width="300dp" android:layout_height="300dp" android:layout_alignParentBottom="true" android:layout_below="@+id/button1" android:layout_centerHorizontal="true" />

MainActivity.java文件 WebView web_view =(WebView)findViewById(R.id.webView1); web_view.getSettings().setLoadWithOverviewMode(true); web_view.getSettings().setUseWideViewPort(true); web_view.loadUrl("google.com";);

最佳答案

您需要更改用户代理以使其不加载移动网站。


试试这个

<WebView android:id="@+id/webView1" android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:layout_alignParentBottom="true" 
android:layout_below="@+id/button1" android:layout_centerHorizontal="true" />

关于android - 如何在 Android 的 WebView 中加载 url 以正确查看?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12058624/

相关文章:

android-emulator - 自定义安卓模拟器

android webkit 改变字体大小?

android - 不要在旋转时重新加载 webview 视频

当 html 具有特殊字符时,Android WebView 无法执行 Javascript ✓

Android Jetpack 组合 IconButton 填充

android - ArrayAdapter 的 getView() 方法没有被调用

添加字体时,Prolog 中不允许使用 Android 的内容

android - 权限拒绝 : permission. MAPS_RECEIVE 由于发件人 com.google.android.apps.maps

Android Studio 模拟器 - Ubuntu 16.04 LTS

android - 以编程方式支持 Android 模拟器的多点触控