【问题标题】:Is it in the Gluon API to keep our app in Portrait Mode even if the user rotates their device in Landscape Mode?即使用户在横向模式下旋转他们的设备,是否在 Gluon API 中保持我们的应用程序处于纵向模式?
【发布时间】:2021-12-02 06:31:31
【问题描述】:

在将我的应用设置为纵向模式后,我发现如果用户操纵手机将应用调用为横向模式,那么它的布局是不可接受的。我可以稍后花时间重写/重新测试纵向和横向模式的 UX,但目前是让我们的应用始终保持纵向模式的一种方式吗?

【问题讨论】:

    标签: javafx gluon-mobile gluonfx


    【解决方案1】:

    目前还没有 API 或 Attach 服务。 但是,您可以修改 AndroidManifest.xml 文件 (Android) 或 Default-Info.plist 文件 (iOS) 以强制使用单一方向,而不是现有的纵向和横向方向。

    安卓

    参考https://docs.gluonhq.com/#_android_2

    AndroidManifest.xml 文件是为具有 gluonfx:package 目标的项目生成的,它位于 target/gluonfx/aarch64-android/gensrc/android。

    将此文件复制到src/android 并进行必要的修改:

    • 肖像
    <?xml version='1.0'?>
    <manifest xmlns:android='http://schemas.android.com/apk/res/android' package='$your_package' android:versionCode='1' android:versionName='1.0'>
        <application android:label='$your_label' android:icon="@mipmap/ic_launcher">
            <activity android:name='com.gluonhq.helloandroid.MainActivity'
        android:configChanges="orientation|keyboardHidden" 
        android:screenOrientation="portrait">
                 <intent-filter>
                    <category android:name='android.intent.category.LAUNCHER'/>
                    <action android:name='android.intent.action.MAIN'/>
                 </intent-filter>
            </activity>
    </manifest>
    
    • 风景
    <?xml version='1.0'?>
    <manifest xmlns:android='http://schemas.android.com/apk/res/android' package='$your_package' android:versionCode='1' android:versionName='1.0'>
        <application android:label='$your_label' android:icon="@mipmap/ic_launcher">
            <activity android:name='com.gluonhq.helloandroid.MainActivity' 
        android:configChanges="orientation|keyboardHidden" 
        android:screenOrientation="landscape">
                 <intent-filter>
                    <category android:name='android.intent.category.LAUNCHER'/>
                    <action android:name='android.intent.action.MAIN'/>
                 </intent-filter>
            </activity>
    </manifest>
    

    然后再次运行gluonfx:package,最终清单将包含更改。

    iOS

    参考https://docs.gluonhq.com/#_ios_2

    配置由键 UISupportedInterfaceOrientationsUISupportedInterfaceOrientations-ipad 定义。默认值:

            <key>UISupportedInterfaceOrientations</key>
            <array>
                    <string>UIInterfaceOrientationPortrait</string>
                    <string>UIInterfaceOrientationLandscapeLeft</string>
                    <string>UIInterfaceOrientationLandscapeRight</string>
                    <string>UIInterfaceOrientationPortraitUpsideDown</string>
            </array>
            <key>UISupportedInterfaceOrientations~ipad</key>
            <array>
                    <string>UIInterfaceOrientationPortrait</string>
                    <string>UIInterfaceOrientationLandscapeLeft</string>
                    <string>UIInterfaceOrientationLandscapeRight</string>
                    <string>UIInterfaceOrientationPortraitUpsideDown</string>
            </array>
    

    添加文件src/main/resources/META-INF/substrate/ios/Partial-Info.plist 并包含以下代码:

    • 肖像
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
            <key>UISupportedInterfaceOrientations</key>
            <array>
                    <string>UIInterfaceOrientationPortrait</string>
                    <string>UIInterfaceOrientationPortraitUpsideDown</string>
            </array>
            <key>UISupportedInterfaceOrientations~ipad</key>
            <array>
                    <string>UIInterfaceOrientationPortrait</string>
                    <string>UIInterfaceOrientationPortraitUpsideDown</string>
            </array>
    </dict>
    </plist>
    
    • 风景
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
            <key>UISupportedInterfaceOrientations</key>
            <array>
                    <string>UIInterfaceOrientationLandscapeLeft</string>
                    <string>UIInterfaceOrientationLandscapeRight</string>
            </array>
            <key>UISupportedInterfaceOrientations~ipad</key>
            <array>
                    <string>UIInterfaceOrientationLandscapeLeft</string>
                    <string>UIInterfaceOrientationLandscapeRight</string>
            </array>         
    </dict>
    </plist>
    

    然后再次运行mvn gluonfx:link,最终的 plist 将包含这些更改。

    【讨论】:

      猜你喜欢
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-11
      • 2012-11-10
      • 1970-01-01
      • 2013-10-17
      相关资源
      最近更新 更多