android - Xamarin Android 仅在手机上将方向锁定为纵向

标签 android android-layout xamarin xamarin.android

我试图将手机大小布局上的整个应用的方向锁定为仅纵向,但在平板电脑大小的布局上允许纵向和横向。

我知道我可以将 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/

相关文章:

android - 如何在 Android 中解析来自 Sdcard 的 xml 文件

java - Android 列表首选项 : have summary as selected value?

android - ios相当于android xml的是什么?

ios - 如何在 RowSelected 事件上导航到 Xamarin iOS 中的 ViewController

xamarin - Xamarin 中的可共享控件/ View

ios - 启动 Xamarin iOS 应用程序失败并显示日志消息 "An error occurred searching types for the given assembly"

android - android gradle 构建配置文件中的 "Missing Time"

android - 需要在 HTML webview 中显示文本格式的数据,如 Stack Overflow

java - Android 水平轮(自定义)DatePicker 中的问题

android - 匹配屏幕宽度和图像高度的可点击图像