【问题标题】:How to avoid device rotation after external app run?外部应用程序运行后如何避免设备旋转?
【发布时间】:2018-11-26 23:07:49
【问题描述】:

我遇到了设备旋转问题。我在横向模式下运行一个应用程序,在 xamarin 中开发,它调用相机设备,拍照并再次返回应用程序并显示它自己的照片库。

问题是设备在相机应用程序之后总是以纵向返回。如果我尝试在横向模式下阻止应用程序,它会在相机之后崩溃,因为这种烦人的旋转,即使图片已保存在正确的存储中。

我创建了一个遮罩来隐藏这种丑陋的效果,但即便如此,它也能在瞬间可见。该应用程序运行完美,没有任何问题,除此之外。

该设备是小米 MiA2 Lite。我认为这是问题所在,但我必须为此开发应用程序。

我在论坛里搜索过,没找到解决办法,但现在我知道Android的默认模式是竖屏,也许是个起点。

有什么解决方案或想法来解决这个问题吗?如有任何帮助,我将不胜感激。

谢谢!

已编辑

我尝试了所有 ConfigChanges 的 OnConfigurationChanged(Configuration newConfig) 没有结果。

public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
    {
        base.OnConfigurationChanged(newConfig);
        switch (newConfig.Orientation)
        {
            case Orientation.Landscape:
                switch (Device.Idiom)
                {
                    case TargetIdiom.Phone:
                        LockRotation(Orientation.Landscape);
                        break;
                    case TargetIdiom.Tablet:
                        LockRotation(Orientation.Landscape);
                        break;
                }
                break;
            case Orientation.Portrait:
                switch (Device.Idiom)
                {
                    case TargetIdiom.Phone:
                        LockRotation(Orientation.Landscape);
                        break;
                    case TargetIdiom.Tablet:
                        LockRotation(Orientation.Landscape);
                        break;
                }
                break;
        }
    }

【问题讨论】:

  • 我猜你的设备是小米,不是 Xamarin。你的应用是原生安卓应用还是 Xamarin 应用?
  • 是的,你是对的,小米。这是一个 Xamarin 应用程序。

标签: c# android xamarin


【解决方案1】:

都是系统摄像头产生的问题。它的布局设计为在纵向模式下运行。更改应用摄像头可解决此错误。

【讨论】:

    猜你喜欢
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    相关资源
    最近更新 更多