有没有一种方法可以使我的Xamarin Forms应用程序仅在纵向模式下工作?

时间:2019-02-20 02:21:00

标签: xamarin xamarin.forms

我有一个在纵向模式下看起来不错但在横向模式下看起来不太好的应用程序。

在表单内或通过自定义渲染器是否可以设置应用程序,使其始终设置为纵向模式?

不确定是否有帮助,但是我正在使用Xamarin Essentials,以防万一可以使用提供的功能来做到这一点。

谢谢

2 个答案:

答案 0 :(得分:2)

xamarin中的设备屏幕方向通常是通过Host(Android / iOS)项目配置的。

在iOS上,使用Info.plist文件为应用程序配置了设备方向。

info.plist

在Android上,打开MainActivity.cs并使用装饰MainActivity类的属性设置方向:

namespace MyRotatingApp.Droid
{
    [Activity (Label = "MyRotatingApp.Droid", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Landscape)] //This is what controls orientation
    public class MainActivity : FormsAppCompatActivity
    {
    }
}

有关更多信息,您可以检查此link

答案 1 :(得分:1)

在android中寻找这个

Activity(ScreenOrientation = ScreenOrientation.Portrait

在android MainActivity中:

  namespace Namespace.Droid
{
    [Activity(ScreenOrientation = ScreenOrientation.Portrait , ...]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
     ...

在Ios Info.pList中:

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>

确保仅保留纵向方向