简体   繁体   English

Phonegap splashscreen方向

[英]Phonegap splashscreen orientation

When setting the splashscreen for a phonegap application, the picture gets stretched across the whole screen, even when i make a big picture with the logo in the center. 为手机屏幕应用程序设置启动画面时,即使我在中心制作了带有徽标的大图片,图片也会在整个屏幕上拉伸。 Ideally I want the picture just sit in the center with a black or white background. 理想情况下,我希望图片只是坐在中心,背景为黑色或白色。 How can I configure the behaviour of the splashscreen? 如何配置启动画面的行为?

There is a better solution available: Simply place the following splash.xml in res/drawable (modify the android:src attribute) and change the reference to R.drawable.splash, in the setIntegerProperty() call. 有一个更好的解决方案:只需将以下splash.xml放在res / drawable中(修改android:src属性)并在setIntegerProperty()调用中更改对R.drawable.splash的引用。

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
  android:src="@drawable/splashImage"
  android:gravity="center_horizontal|center_vertical" />

Please see my Blog for a more detailed description of the set-up. 请参阅我的博客以获取有关设置的更详细说明。

I just set the splash screen based on the current orientation on startup. 我只是根据启动时的当前方向设置启动画面。 Not perfect, but works. 不完美,但有效。 You could go further and ad on orientation change the same effect, but the chances of someone changing orientation during splash screen startup is slim. 你可以更进一步,广告取向改变相同的效果,但有人在启动画面启动期间改变方向的机会很小。

int ot = getResources().getConfiguration().orientation;

        if (ot == 2) {
            super.setIntegerProperty("splashscreen", R.drawable.splashlandscape);
            Log.d("Orientation", "Landscape");
        }
        else {
            super.setIntegerProperty("splashscreen", R.drawable.splashportrait);
            Log.d("Orientation", "Portrait");
        }

This is a solution but it has flaws 这是一个解决方案,但它有缺陷

put your splash.png in the various drawable folders 把你的splash.png放在各种可绘制的文件夹中

res/drawable/splash.png (480wx800h portrait version)
res/drawable-land/splash.png (800wx480h landscape version)

known issue with this method is if the orientation changes after load it doesn't update the background... (this is true for phonegap 1.10) 这种方法的已知问题是如果方向在加载后发生变化则不会更新背景...(对于phonegap 1.10也是如此)

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

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