在 Xamarin.Android 中检查它是否处于横向或纵向模式的方法 [英] A way to check if it is in the landscape or portrait mode in Xamarin.Android

查看:40
本文介绍了在 Xamarin.Android 中检查它是否处于横向或纵向模式的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using C# in Visual Studio 2017 and Xamarin.Android (not Xamarin.Forms) in my project. To be clear, I'm using "Cross Platform App(Xamarin)" and not using "Class Library (Xamarin.Forms). I want it to work on both IOs and Android.

我的问题是我想将我的应用程序编程为在横向模式下看起来像 ^ ^ 并且 <^ 竖屏模式(请像竖屏模式一样查看).基本上我想旋转第一个并将其放在顶部,而不想更改第二个并将其放在底部.

My problem is I want to program my app to look like ^ ^ in landscape mode and < ^ in portrait mode(please look at it like it is in portrait mode). Basically I want to rotate the first one and put it on top, and doesn't wanna change the second one and put it on the bottom.

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

I searched for a way that how to check if it is in the landscape or portrait mode. Everything that I found in the forums suggest me to use a function that is in Xamarin.Forms, even Xamarin University itself. But I cannot create a new project and carry each class into it. Is there any way that you know how to check if it is in the landscape or portrait mode in Xamarin.Droid?

推荐答案

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

To control the orientation on Android, open MainActivity.cs and set the orientation using the attribute 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)
}

这篇关于在 Xamarin.Android 中检查它是否处于横向或纵向模式的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆