gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:14:51 24 4
gpt4 key购买 nike

当我的 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/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com