如何使用KitKat使文本适合WebView中的屏幕(文本换行) [英] How to make text fit to screen (text-wrap) in WebView with KitKat

查看:94
本文介绍了如何使用KitKat使文本适合WebView中的屏幕(文本换行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Android 4.4的WebView中遇到问题.在使用KitKat之前,文本会自动适应Web视图中所有设备的分辨率.但是今天,它不再适合4.4.我认为这是由于基于KitKit的Chromium的WebView的更新.

I'm having an issue in my WebView with Android 4.4. Before KitKat, text was fitting automatically with all devices resolutions in webviews. But today it's not fitting automatically anymore with 4.4. I think it's because of the WebView's update based on Chromium with KitKat.

这是同一页面的2个屏幕截图:

Here are 2 screenshots of the same page :

一个来自Galaxy Nexus(Android 4.3)的手机

一个来自Nexus 5(Android 4.4和基于Chromium的WebView)

您知道在webview中是否有一个新的选项来使文本适合屏幕显示?

Do you know if there is a new option to fit text with screen in webview ?

NB:我不认为我的布局与我的问题有关,但无论如何这里都是这样:

NB: I don't think my layout as something to do with my issue but here it is anyway:

<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中已已弃用.

It looks like this is using NARROW_COLUMNS. This was deprecated in KitKat.

但是,添加了一个新的布局算法,该算法可能可以解决此问题,此处有一个示例: https://github.com/GoogleChrome/chromium-webview-samples

However, a new layout algorithm was added which might be able to fix this, there is an example here: 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);

另一个选项是启用捏合缩放:

The other option is to enable pinch zoom:

// 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);
}

新的布局算法可能无法解决所有问题,并且不清楚如何可靠地模仿旧的包装行为.

The new layout algorithm may not solve all the problems and it's not clear how to reliably mimic the old wrapping behavior.

大多数异议似乎是在移动设备上显示桌面网站的一般浏览器问题.他们喜欢旧的方式,但是我还没有看到其他浏览器能够像文本包装算法那样工作.

The majority of the objections seem like general browser issues of displaying desktop sites on mobile. They liked the old way, but I have not seen a single other browser do what the text-wrapping algorithm was doing.

这篇关于如何使用KitKat使文本适合WebView中的屏幕(文本换行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆