cordova - Android的Phonegap启动画面: not stretched or 9patch

标签 cordova screen stretch splash-screen nine-patch

当我的 phonegap 应用程序启动时,我有一个假的闪屏:

super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("file:///android_asset/www/index.html", 500);

我目前有 3 个不同的 splash.png 文件:hdpi、mdpdi 和 ldpi。我的问题是,即使在 hdpi 中,您也会获得 480 x 800 和其他 480 x 854 的设备,并且 android 会拉伸(stretch)我的启动图像以填满屏幕。

我宁愿让图像保持其纵横比。根据我的阅读,9 补丁解决方案不适用于 PhoneGap。如果会,请告诉我如何!我已经准备好 .9.png 了。
所以我能想到的另一个解决方案是防止android拉伸(stretch)我的图像。我该怎么做?

谢谢!

最佳答案

9 补丁解决方案确实适用于 PhoneGap 中的闪屏 :-)

  • 通过创建一个 xml 文件来定义一个新的可绘制资源,即 res/drawable/splash.xml 具有以下内容:
    <nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/splashimg" 
    android:dither="false"/>;  
    

    请注意它是如何引用真实图像“splashimg”的,该图像应该是 9-patch 图像(见下文)。
  • 创建 9-patch 图像
  • 任何png都可以。
  • 然后使用 android-sdks/tools/draw9patch 定义 9-patch 边框
    (见 http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch )
  • 重要提示:这些图像必须将填充框(下边框和右边框)完全填充为黑色,否则应用程序的 phonegap 区域可能会以一种奇怪的方式拉伸(stretch)。
  • 在 res/drawable 或分辨率特定文件夹中添加引用的 9-patch 图像
    例如res/drawable/splashimg.9.png
  • 在您的 DroidGap 扩展类中引用新的可绘制对象
    public void onCreate(Bundle savedInstanceState) {
    
        super.setIntegerProperty("splashscreen", R.drawable.splash);
    
    }
    

  • 通过这种方式,您实际上可以通过使用 android 中可绘制资源的强大功能来制作各种背景图像/效果。见 http://developer.android.com/guide/topics/resources/drawable-resource.html更多。

    关于cordova - Android的Phonegap启动画面: not stretched or 9patch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9204573/

    相关文章:

    javascript - 灰度 css 不适用于 android

    html - 尝试向下拉伸(stretch)背景,但仍留有空白

    javascript - document.addEventListener ("touchmove",阻止行为,假); - 阻止我使用溢出 : scroll; - work around?

    cordova - 如何安装 Cordova ?

    C++ 屏幕截图 - 如何读取位图?

    android - 以编程方式解锁 Android 手机?

    android - 在 Android 中以编程方式使用屏幕截图时保存空白文件

    c++ - 这是在 Windows 中将大型 DIB 绘制到屏幕上的最快方法

    C# Winforms 获取表单的拉伸(stretch)背景图像

    javascript - 就绪状态始终为 0