在将我的应用程序设置为纵向模式后,我发现如果用户操纵手机将应用程序调用为横向模式,它的布局是不可接受的。我可以稍后花时间重写/重新测试纵向和横向模式的 UX,但目前是我们让我们的应用程序一直保持纵向模式的一种方式吗?
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以供参考。
配置由键UISupportedInterfaceOrientations
和定义UISupportedInterfaceOrientations-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 将包含这些更改。