【问题标题】:Landscape splash screen for Android in PhoneGap BuildPhoneGap Build 中 Android 的横向闪屏
【发布时间】:2013-01-28 10:42:52
【问题描述】:

我应该在config.xml 中输入什么,或者我一般应该怎么做,才能让PhoneGap Build 应用程序的启动屏幕在Android 设备上以横向模式正确显示?

PhoneGap Build(用于编译)docs / blog 对此一无所知。 Android 仅涵盖肖像。

因为首先(文档)说使用heightwidth 是支持跨平台的,所以我尝试使用它:

<gap:splash src="res/splash-200x320-android.png"             gap:platform="android" gap:density="ldpi"  width="200" height="320" />
<gap:splash src="res/splash-320x480-android-bada-ios.png"    gap:platform="android" gap:density="mdpi"  width="320" height="480" />
<gap:splash src="res/splash-480x800-android-bada-wp.png"     gap:platform="android" gap:density="hdpi"  width="480" height="800" />
<gap:splash src="res/splash-720x1280-android.png"            gap:platform="android" gap:density="xhdpi" width="720" height="1280" />
<gap:splash src="res/splash-320x200-android.png"             gap:platform="android" gap:density="ldpi"  width="320" height="200" />
<gap:splash src="res/splash-480x320-android-bada-ios.png"    gap:platform="android" gap:density="mdpi"  width="480" height="320" />
<gap:splash src="res/splash-800x480-android-bada-wp.png"     gap:platform="android" gap:density="hdpi"  width="800" height="480" />
<gap:splash src="res/splash-1280x720-android.png"            gap:platform="android" gap:density="xhdpi" width="1280" height="720" />

但没有任何效果——在我的 Android 设备上的横向模式下,我总是看到我的初始屏幕的 strechead portait 模式版本很糟糕。

【问题讨论】:

    标签: cordova landscape phonegap-build splash-screen


    【解决方案1】:

    根据我目前的知识和深入研究,我发现这是一个已确认的错误,我们目前对此无能为力。

    PhoneGap Build(可能还有 PhoneGap 本身)目前根本不支持横向闪屏。我什至尝试了 iOS 方式(如问题所示——使用 widthheight 参数,Android 官方不支持)。但是还是不行。

    在纵向模式下一切正常,但无论您使用何种屏幕密度的 Android 设备 - 在横向模式下,您都会看到丑陋的变形纵向版本的初始屏幕。

    【讨论】:

      【解决方案2】:

      我没有使用 PhoneGap Build,但我设法在一个基本的 PhoneGap Android 应用中解决了这个问题。

      假设您有两个不同的初始图像 - 横向和纵​​向版本 - 并且您希望它们都拉伸以填充可用的屏幕区域。

      将一个放入drawable,另一个放入drawable-land。 (或drawable-land-hdpidrawable-land-xhdpi 等,如果您有多种尺寸。)

      接下来,请确保您自己在 AndroidManifest.xml 中管理配置更改:

      <activity
          ...
          android:configChanges="orientation|screenSize|keyboardHidden"
          ...
      >
      </activity>
      

      然后把它放在扩展DroidGap.java的主Activity类中:

      @Override
      public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
      
          if (super.splashDialog != null) {
              ViewGroup rootView = (ViewGroup) super.splashDialog.getWindow()
                      .getDecorView().findViewById(android.R.id.content);
              LinearLayout linearLayout = (LinearLayout) rootView.getChildAt(0);
              // manually refresh the splash image
              linearLayout.setBackgroundDrawable(null);
              linearLayout.setBackgroundResource(R.drawable.mysplash);
          }
      }
      

      这将导致背景图像在用户改变方向时重新绘制并正确拉伸。

      【讨论】:

      • 这是一个很好看的解决方案(所以 +1),但我不会接受它,因为它太离题了。我的问题的想法是为PhoneGap Build 提供特定的答案——也就是说,只使用HTML/Javascript 和config.xml。您没有能力在 PhoneGap Build 应用程序中使用纯 Java 代码,不是吗?
      • @LarryAasen 不,你不能!阅读我的评论。我说的是PhoneGap Build。使用PGB(在云中构建)时,您只能使用 HTML/Javascript。如果您在自己的环境中本地构建,则只能使用纯 Java 代码。
      • @trejder 如果是这种情况,您需要重新表述您的问题以包括构建。否则,我的评论是正确的。
      • @LarryAasen 我用过:PhoneGap Build(用于编译) 部分我的问题和答案的作者,你在评论(nlawson)他的回答开头是:我没有使用 PhoneGap Build,但是...。似乎大多数人都明白,这个问题仅与 PhoneGap Build 有关。但是,如果这会让你开心,我认为更改问题的标题没有问题! :]
      【解决方案3】:

      Phonegap Build 现在使用Cordova configuration style。在指定density 时,附加port-land- 以指定纵向或横向:

      <splash src="portrait-ldpi.png" density="port-ldpi"/>
      <splash src="landscape-ldpi.png" density="land-ldpi"/>
      

      老配置风格

      从 2014 年 4 月开始,可以使用 gap:qualifer 在 Phonegap Build 中完成,例如

      <gap:splash src="portrait-xxhdpi.png" gap:platform="android" gap:qualifier="port-xxhdpi" />
      <gap:splash src="landscape-xxhdpi.png" gap:platform="android" gap:qualifier="land-xxhdpi" />
      

      详情请参阅thisthis 文章。

      【讨论】:

        猜你喜欢
        • 2018-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-04
        • 1970-01-01
        相关资源
        最近更新 更多