Android的web视图 - 网页应该适应手机屏幕 [英] Android Webview - Webpage should fit the device screen

查看:227
本文介绍了Android的web视图 - 网页应该适应手机屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试以下根据设备屏幕大小,使其适合网页。

I have tried the following to fit the webpage based on the device screen size.

mWebview.setInitialScale(30);

,然后将元数据视

and then set the metadata viewport

<meta name="viewport" content="width=320, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;"/>
<meta name="viewport" content="width=device-width, target-densityDpi=medium-dpi"/>

但没有任何工程,网页是不是固定在设备的屏幕尺寸。

But nothing works, webpage is not fixed to the device screen size.

谁能告诉我怎么走呢?

推荐答案

你算算,你需要手动操作,而不是设置到30的规模。

You have to calculate the scale that you need to use manually, rather than setting to 30.

private int getScale(){
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
    int width = display.getWidth(); 
    Double val = new Double(width)/new Double(PIC_WIDTH);
    val = val * 100d;
    return val.intValue();
}

然后使用

WebView web = new WebView(this);
web.setPadding(0, 0, 0, 0);
web.setInitialScale(getScale());

这篇关于Android的web视图 - 网页应该适应手机屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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