无法通过 Xamarin 让 Surface Duo 使用两个屏幕
我正在尝试为 Surface Duo 构建一个 Xamarin Forms 项目。该项目可以运行,但不会同时使用两个屏幕。我按照 Xamarin for Surface Duo - 双屏 | Microsoft Docs 中的步骤进行操作:
-
更新了指向 SDK 的指针。
-
将
Xamarin.Forms.DualScreen.DualScreenService.Init(this);
添加到mainactivity.cs
。 -
修改了 Activity 属性以包含:
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.UiMode
。 -
在 Android 应用程序中包括 Xamarin.DuoSdk 包。
-
在阅读模拟器输出时,有一行建议使用 bcdedit 命令关闭 hyper-V,我照做了。
-
选择了
<build>
(Android 10.0 – API 29)
我下载了一些示例(Sketch 360 和双屏演示),但没有成功让它们使用两个屏幕。我按照 Get 上发布的运行演示,并更新了包,但没有成功。我检查了模拟器中的手机设置,看看是否有启用两个屏幕的设置,但没有找到任何东西。模拟器输出中有一些错误和警告,但不确定如何修复它们。
模拟器输出
emulator: Silencing all qWarning(); use qCWarning(...) instead: QT_LOGGING_RULES=default.warning=false
Failed to open /qemu.conf, err: 2
emulator: INFO: QtLogger.cpp:68: Critical: UpdateLayeredWindowIndirect failed for ptDst=(1283, 327), size=(700x21), dirty=(700x108 0, 0) (A device attached to the system is not functioning.) ((null):0, (null))
emulator: INFO: QtLogger.cpp:68: Critical: UpdateLayeredWindowIndirect failed for ptDst=(1283, 327), size=(700x21), dirty=(700x21 0, 0) (A device attached to the system is not functioning.) ((null):0, (null))
emulator: INFO: QtLogger.cpp:68: Critical: Uncaught TypeError: Cannot read property 'update' of undefined (qrc:/html/js/location-mock-web-channel.js:130, (null))
构建输出
System.InvalidCastException: Unable to cast object of type 'Mono.Debugger.Soft.PointerValue' to type 'Mono.Debugger.Soft.PrimitiveValue'.
System.InvalidCastException: Unable to cast object of type 'Mono.Debugger.Soft.PointerValue' to type 'Mono.Debugger.Soft.PrimitiveValue'.
System.InvalidCastException: Unable to cast object of type 'Mono.Debugger.Soft.PointerValue' to type 'Mono.Debugger.Soft.PrimitiveValue'.
02-06 20:34:52.574 W/libc ( 3873): Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
02-06 20:34:54.961 W/OpenGLRenderer( 3873): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
如果您询问如何让应用以编程方式使用两个屏幕,而不是用户在启动应用后采取行动,那么这是无法做到的。
请参阅此处的解释: https://learn.microsoft.com/en-us/dual-screen/introduction
When the user launches an app, its core window opens maximized and occupies the full width and height of a single screen.
The user is responsible for spanning the app, it's not a state the app enters programmatically.
Users are always in control: In order to avoid unpredictable (or potentially destructive) experiences for your users, apps shouldn't automatically enter a spanned state without an intentional, user-initiated action. Let the user decide.
运行
Surface Duo Emulator for Visual Studio
以启动 Surface Duo 模拟器。如果您对模拟器有任何问题,可以使用以下链接进行故障排除。
https://learn.microsoft.com/en-us/dual-screen/xamarin/use-emulator?tabs=windows#update-the-pointer-to-your-android-sdk
通过 NuGet 安装包。
Xamarin.Forms.DualScreen
:
https://www.nuget.org/packages/Xamarin.Forms.DualScreen
使用如下所示的 xaml。
<dualScreen:TwoPaneView>
<dualScreen:TwoPaneView.Pane1>
<StackLayout>
<Label Text="Pane1 Content" />
</StackLayout>
</dualScreen:TwoPaneView.Pane1>
<dualScreen:TwoPaneView.Pane2>
<StackLayout>
<Label Text="Pane2 Content" />
</StackLayout>
</dualScreen:TwoPaneView.Pane2>
</dualScreen:TwoPaneView>
使用模拟器
<build> 运行项目 (Android 10.0 – API 29)