我的WebView与
Android 4.4有一个问题.在KitKat之前,文本会自动适应网页浏览中的所有设备分辨率.但今天4.4中已经不再适合了.我认为这是因为WebView基于Chromium与KitKat的更新.
这是同一页面的2个截图:
One from Galaxy Nexus (Android 4.3)
One from Nexus 5 (Android 4.4 and WebView based on Chromium)
你知道在webview中是否有一个新的选项来适应文字与屏幕?
注意:我不认为我的布局与我的问题有关,但在这里呢?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
解决方法
看起来这是使用NARROW_COLUMNS.这是在KitKat的
deprecated.
但是,添加了一种新的布局算法,可以解决这个问题,这里有一个例子:
https://github.com/GoogleChrome/chromium-webview-samples
主要代码是:
// Use WideViewport and Zoom out if there is no viewport defined settings.setUseWideViewPort(true); settings.setLoadWithOverviewmode(true); settings.setLayoutAlgorithm(LayoutAlgorithm.TEXT_autosizing);
另一个选项是启用压缩缩放:
// Enable pinch to zoom without the zoom buttons
settings.setBuiltInZoomControls(true);
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
// Hide the zoom controls for HONEYCOMB+
settings.setdisplayZoomControls(false);
}
新的布局算法可能无法解决所有问题,并不清楚如何可靠地模拟旧的包装行为.
大多数反对意见似乎是在移动设备上显示桌面版网站的一般浏览器问题.他们喜欢旧的方式,但是我还没有看到另外一个浏览器执行了文本包装算法正在做的事情.