【问题标题】:A way to check if it is in the landscape or portrait mode in Xamarin.Android一种在 Xamarin.Android 中检查它是处于横向还是纵向模式的方法
【发布时间】:2017-07-25 19:11:08
【问题描述】:

我在 Visual Studio 2017 中使用 C#,在我的项目中使用 Xamarin.Android(不是 Xamarin.Forms)。需要明确的是,我使用的是“跨平台应用程序(Xamarin)”,而不是使用“类库(Xamarin.Forms)。我希望它可以在 IO 和 Android 上运行。

我的问题是我想将我的应用程序编程为在横向模式下看起来像 ^ ^ 并且

我搜索了一种方法来检查它是处于横向还是纵向模式。我在论坛中找到的所有内容都建议我使用 Xamarin.Forms 中的函数,甚至 Xamarin 大学本身。但是我无法创建一个新项目并将每个类都带入其中。有什么方法知道如何检查 Xamarin.Droid 中它是处于横向模式还是纵向模式?

【问题讨论】:

    标签: xamarin xamarin.ios xamarin.android


    【解决方案1】:

    要在 Android 上控制方向,请打开 MainActivity.cs 并使用属性 decorating 设置方向。

     namespace MyRotatingApp.Droid
    {
        [Activity (Label = "MyRotatingApp.Droid", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
        ScreenOrientation = ScreenOrientation.Landscape)] **//This is what controls orientation**
        public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
        {
            protected override void OnCreate (Bundle bundle)
    }
    

    【讨论】:

    • 在“global::Xamarin.Forms.Platform.Android.FormsApplicationActivity”处,它在Forms 处出现错误并显示“类型或命名空间名称”Forms 在命名空间“Xamarin”中不存在“。我说我在我的项目中使用 Xamarin.Android(不是 Xamarin.Forms)。也许这可能是问题所在?它也会在 ConfigChanges 处出现错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    • 2012-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多