简体   繁体   English

如何使PhoneGap Android APP适应所有设备?

[英]How do I make my PhoneGap Android APP fit all devices?

I built my APP as was instructed using Cordova, and I can't get the HTML pages I make to fit the scree, they're always larger. 我按照Cordova的指示构建了我的APP,但我无法获得适合该屏幕的HTML页面,它们总是很大。

This is the generated Android App Code, and there was no .xml file generated for layout 这是生成的Android应用代码,并且没有生成用于布局的.xml文件

public class APP extends CordovaActivity 
{
  @Override
  public void onCreate(Bundle savedInstanceState)
    {   
    super.onCreate(savedInstanceState);
    super.init();
    // Set by <content src="index.html" /> in config.xml
    super.loadUrl(Config.getStartUrl());
    //super.loadUrl("file:///android_asset/www/index.html");
    }
}

And I put this in the Meta tag, of the HTML file. 然后将其放在HTML文件的Meta标记中。

  <meta name="viewport" content="height=device-height,width=device-width,initial-scale=1.0,maximum-scale=1.0" >

Running this App gives me an app that is much bigger than the size of the screen, also I use JQuery Mobile to structure the HTML, any solutions would be much appreciated. 运行此应用程序将为我提供一个比屏幕大小大得多的应用程序,而且我使用JQuery Mobile构建HTML,任何解决方案都将不胜感激。


Usually I want pages not to have a page width of 800 to 900 pixels, as the Android and iPhone browsers set it to by default. 通常,我不希望页面的页面宽度为800到900像素,因为Android和iPhone浏览器默认将其设置为。 To have the page width the same as the device width, I set the following meta tags: 为了使页面宽度与设备宽度相同,我设置了以下元标记:

<meta name="HandheldFriendly" content="true" />
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />

Also refer https://developer.android.com/guide/webapps/targeting.html 另请参阅https://developer.android.com/guide/webapps/targeting.html

While not much can be suggested to you unless you show us your HTML and CSS code, this is a common problem when creating apps using web technologies for devices with vastly different screen resolutions. 除非您向我们展示您的HTML和CSS代码,否则对您的建议不多,但这是在使用Web技术为屏幕分辨率差异很大的设备创建应用程序时常见的问题。

One work around would be to define the dimensions of UI elements in em units instead of px . 解决方法之一是以em单位而不是px定义UI元素的尺寸。 Then you could set appropriate base font-size for different screen resolutions using CSS media queries or JavaScript 然后,您可以使用CSS媒体查询或JavaScript为不同的屏幕分辨率设置适当的基本font-size

use this one 用这个

<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" name="viewport">

100% works. 100%有效。 you can view my app here. 您可以在这里查看我的应用。

http://www.revivalx.com/my/#home http://www.revivalx.com/my/#home

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM