的WebView的Andr​​oid 4.4系统和初始规模 [英] WebView in Android 4.4 and initial-scale

查看:156
本文介绍了的WebView的Andr​​oid 4.4系统和初始规模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在敲打我的头撞墙了整整一天了,我需要一些帮助:(

I've been banging my head against the wall for the whole day now, and i need some help :(

现在的问题是,我有一个是专为一个Web应用程序 640×960

The problem is, that i have a WebApp that was designed for 640x960.

我们没有时间来写CSS的每一个屏幕尺寸,所以我在<$使用初始规模,最大规模,最低规模 C $ C>视 meta标签扩展的应用程序,以不同的屏幕尺寸。

We didn't have time to write css for each screen size, so i've used initial-scale, maximum-scale, minimum-scale in the viewport meta tag to scale the app to different screen sizes.

现在的问题是,在Android的 4.4 ,无论我做什么,它总是扩展应用程序了,但从来没有失望!

The problem is, that in Android 4.4, no matter what i do, it always scales the app up, but never down!

我的意思是,如果我用 0.7 ,应用程序被放大的值。如果我使用的值 1.3 ,这是扩大规模再次:/

I mean if i use a value of 0.7, the app is scaled up. If i use a value of 1.3, it is scaled up again :/

我试图修改 targetSdkVersion 不同版本得到旧的行为,但没有运气。

I've tried to change the targetSdkVersion to different versions to get the old behavior, but with no luck.

有人能帮助我吗?

更新: 所以,我结束了使用风格=缩放:其中;价值&GT;%标记。余计算基于当前设备屏幕大小和我的应用程序被设计为分辨率之间的差异的百分比。现在一切都适合。

UPDATE: So i ended up using style="zoom: <value>%" on the body tag. I calculate the percentage based on the difference between the current device screen size and the resolution my app was designed for. Now everything fits.

推荐答案

中视区

<meta name="viewport" content="width=640, initial-scale=1">

应该让你的固定布局总是配合(见 MDN 了解的视meta标签)。

should make your fixed layout always fit (see MDN for more on the viewport meta tag).

您可以在碰撞部分如下:

You could be bumping in some of the following:

  • 的内容不能被缩小比概述规模更多(也就是,使得内容是窄于屏幕)。这是由设计 - 使得它更小的只有结果呈现白色的边,何必呢。如果你想这种行为你需要添加填充的内容,
  • 您已经指定要WRAP_CONTENT web视图的布局高度 - 这使得web视图忽略视区meta标签,不这样做 - 将其设置为MATCH_PARENT或固定的大小,
  • 您正在使用某些 WebSettings
    • setUseWideViewport (它覆盖了视区meta标签)或
    • setInitialScale (它可以改变视口的大小)。
    • the contents can't be scaled down more than 'overview scale' (that is, such that your content is narrower than the screen). This is by design - making it smaller only results in rendering white to the sides so why bother. If you want this behaviour you'd need to add padding to the content,
    • you've specified the layout height of the WebView to be WRAP_CONTENT - this makes the WebView ignore the viewport meta tag, don't do that - set it to MATCH_PARENT or a fixed size,
    • you're using certain WebSettings:
      • setUseWideViewport (which overrides the viewport meta tag) or
      • setInitialScale (which can alter the size of the viewport).

      最好的方法来检查,如果它的内容的故障或web视图的错是看网页作品在Chrome浏览器在Android:

      The best way to check if it's the content's fault or the WebView's fault is to see if the page works in Chrome on Android:

      1. 如果它在Chrome浏览器在Android上,但不是在web视图然后设置 targetSdkVersion 19,并尝试禁用WebSettings,改变你的布局,以固定的大小,等等。看是什么导致了问题。通过超级琐碎的WebView应用程序,只需加载页面 - - 确认工作,然后慢慢开始发生变化,看看哪一个会导致​​该问题,
      2. 也许从另一端开始
      3. 如果它不能在Chrome Android上工作,那么问题出在pre-KK的WebView和Chrome在Android上的视区meta标签支持的区别 - 这意味着你必须要修好你的内容,
      1. if it works in Chrome on Android but not in the WebView then set targetSdkVersion to 19 and try disabling WebSettings, changing your layout to fixed size, etc.. to see what's causing the problem. Maybe start from the other end - by making a super trivial WebView app that just loads the page - confirm that works and then slowly introduce changes to see which one causes the problem,
      2. if it doesn't work in Chrome on Android then problem is the difference in viewport meta tag support between pre-KK WebView and Chrome on Android - this means you'll have to fix your content,

      如果你还停留后,包含信号源,摄制一个zip(并不一定是完整的应用程序,只需最低至说明问题),我可以尝试,并帮助您更从那里。

      If you're still stuck post a zip that contains sources with a repro (doesn't have to be the full app, just the minimum to demonstrate the problem) and I can try and help you more from there.

      这篇关于的WebView的Andr​​oid 4.4系统和初始规模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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