A way to check if it is in the landscape or portrait mode in Xamarin.Android

一个人想着一个人 提交于 2019-12-11 05:36:20

问题


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.

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?


回答1:


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)
}


来源:https://stackoverflow.com/questions/45295538/a-way-to-check-if-it-is-in-the-landscape-or-portrait-mode-in-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!