WebView自适用屏幕

可以通过设置LayoutAlgorithm的布局模式来控制WebView

SDK给的方法解释:Sets the underlying layout algorithm. This will cause a relayout of the WebView. The default is {@link LayoutAlgorithm#NARROW_COLUMNS}.

LayoutAlgorithm有三种模式可以选择:

1、LayoutAlgorithm.NARROW_COLUMNS 列宽尽可能的窄,但页面很大的话还是会超过手机的屏幕(默认方式)

2、LayoutAlgorithm.SINGLE_COLUMN 只有一列,宽度与手机屏宽度一样

3、LayoutAlgorithm.NORMAL 正常显示,WebView不作处理


可以设置mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);使H5页面适用手机屏幕大小。


还有人说可以通过一下方法设置自适应

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

我试了,但是没有达到预期的效果

SDK对这两个方法的描述是这样的:

    /**
     * Sets whether the WebView should enable support for the "viewport"
     * HTML meta tag or should use a wide viewport.
     * When the value of the setting is false, the layout width is always set to the
     * width of the WebView control in device-independent (CSS) pixels.
     * When the value is true and the page contains the viewport meta tag, the value
     * of the width specified in the tag is used. If the page does not contain the tag or
     * does not provide a width, then a wide viewport will be used.
     *
     * @param use whether to enable support for the viewport meta tag
     */
    public synchronized void setUseWideViewPort(boolean use) {
        throw new MustOverrideException();
    }


/**
     * Sets whether the WebView loads pages in overview mode, that is,
     * zooms out the content to fit on screen by width. This setting is
     * taken into account when the content width is greater than the width
     * of the WebView control, for example, when {@link #getUseWideViewPort}
     * is enabled. The default is false.
     */
    public void setLoadWithOverviewMode(boolean overview) {
        throw new MustOverrideException();
    }

这里没有深入研究。希望大神指导







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值