问题
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