如何复制 Android 的股票相机方向变化
How to replicate Androids stock camera orientation change
我有三星 Edge,API 24,Android 7.0 和三星平板电脑,API 24,Android 7.0。
如果您不想了解背景故事,请跳过此引用部分:
I want to recreate the stock camera and implement it into my app. I'm
actually very close to having it finished (using Xamarin.Android +
C#), using the Xamarin Version of the Google Camera Sample.
However there are orientation problems left... 180° rotations
(landscape -> reverse landspace or vice versa) don't trigger the
"SurfaceChanged" event, which is used to set the matrix of the surface
to make it display correctly.
I've seen different approaches, one seems stable: Fix the orientation
to landscape and handle orientations myself.
查看我的两个设备的库存相机,我发现相机预览从不移动一点,只有按钮旋转 + activity(状态栏在方向更改时移动到顶部)
如何实现这种行为?
用 Java 或 C# 编写的抽象概念或代码片段会很好。
修复开始时的 activity 方向(例如,在 onResume
方法内):
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
在 AndroidManifest.xml
中指定您希望 activity 监听方向变化:
<activity
android:configChanges="keyboardHidden|orientation|screenSize"
...
然后处理里面的方向变化 activity:
@Override
public void onConfigurationChanged(Configuration newConfig) {
// rotate buttons using newConfig.orientation value
}
我有三星 Edge,API 24,Android 7.0 和三星平板电脑,API 24,Android 7.0。
如果您不想了解背景故事,请跳过此引用部分:
I want to recreate the stock camera and implement it into my app. I'm actually very close to having it finished (using Xamarin.Android + C#), using the Xamarin Version of the Google Camera Sample.
However there are orientation problems left... 180° rotations (landscape -> reverse landspace or vice versa) don't trigger the "SurfaceChanged" event, which is used to set the matrix of the surface to make it display correctly.
I've seen different approaches, one seems stable: Fix the orientation to landscape and handle orientations myself.
查看我的两个设备的库存相机,我发现相机预览从不移动一点,只有按钮旋转 + activity(状态栏在方向更改时移动到顶部) 如何实现这种行为?
用 Java 或 C# 编写的抽象概念或代码片段会很好。
修复开始时的 activity 方向(例如,在 onResume
方法内):
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
在 AndroidManifest.xml
中指定您希望 activity 监听方向变化:
<activity
android:configChanges="keyboardHidden|orientation|screenSize"
...
然后处理里面的方向变化 activity:
@Override
public void onConfigurationChanged(Configuration newConfig) {
// rotate buttons using newConfig.orientation value
}