我正在加载 http://www.google.com
WebView 中的 url。
但是,即使我从设备/模拟器加载它,webview 的内容也不会根据设备尺寸进行调整。
如果您看到,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/