我试图将手机大小布局上的整个应用的方向锁定为仅纵向,但在平板电脑大小的布局上允许纵向和横向。
我知道我可以将 Activity 归因于使用特定方向,但这适用于两种布局尺寸。
[Activity(
Label = "Brs.Members.Droid"
, MainLauncher = true
, Icon = "@mipmap/icon"
, Theme = "@style/Theme.Splash"
, NoHistory = true
, ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashScreen : MvxSplashScreenActivity
{
public SplashScreen() : base(Resource.Layout.SplashScreen)
{
}
}
有没有一种方法可以只排除手机大小设备上的横向布局?
最佳答案
尝试下面的代码,首先检查您的设备是否是平板电脑,然后设置方向:
[Activity(Label = "MyOrientationDemo", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
if (!isPad(this))
{
RequestedOrientation = ScreenOrientation.Portrait;
}
SetContentView (Resource.Layout.Main);
}
public static bool isPad(Context context)
{
return (context.Resources.Configuration.ScreenLayout& ScreenLayout.SizeMask)>= ScreenLayout.SizeLarge;
}
}
关于android - Xamarin Android 仅在手机上将方向锁定为纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42370647/