【问题标题】:Android handling orientation change, if screen lockedAndroid 处理方向变化,如果屏幕锁定
【发布时间】:2018-04-09 18:52:27
【问题描述】:

我有一个相机活动,我不会锁定这个视图的方向。我是这样做的:

[Activity(Label = "Camera Android", MainLauncher = false, NoHistory = false, Theme = "@style/MyThema",
        ScreenOrientation = ScreenOrientation.Portrait,
        ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
    public class FullScreenView : MvxActivity<CameraViewModel>
    {
    ..
    }

现在我有两个问题:
1 - 如果方向已更改,我想旋转此视图中的图标。
2 - 所有照片将仅以纵向模式保存。

如果我为活动编写,则不会调用此方法

ScreenOrientation = ScreenOrientation.Portrait,

public override void OnConfigurationChanged(Configuration newConfig)
{
   base.OnConfigurationChanged(newConfig);
}

OrientationEventListener

也不要工作。 我该怎么办?

【问题讨论】:

    标签: android xamarin.android


    【解决方案1】:

    我使用设备加速度计解决了这个问题。 在项目中我使用 Mvvmcross 并安装了 MvvmCross Accelerometer 插件。

    public interface IMvxAccelerometer
    {
        void Start();
        void Stop();
        bool Started {
            get;
        }
        MvxAccelerometerReading LastReading {
            get;
        }
        event EventHandler<MvxValueEventArgs<MvxAccelerometerReading>> ReadingAvailable;
    }
    

    在代码中我读取设备的 X 和 Y 位置并更改图标和存储照片的方向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-13
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多