【问题标题】:Keeping the current orientation保持当前方向
【发布时间】:2014-05-15 11:27:05
【问题描述】:
我的应用执行以下操作:
- 我拍照
- 图片显示在 DialogFragment 中
如果我在横向模式下拍照,我希望将显示我的图像的 DialogFragment 的方向锁定为横向模式。
如果我以纵向模式拍摄图像,我希望将 DialogFragment 的方向锁定为纵向模式。
这可能吗?
【问题讨论】:
标签:
android
screen-orientation
android-dialogfragment
android-orientation
orientation-changes
【解决方案1】:
检查图片的宽度和高度,这足以告诉您它是在纵向还是横向模式下拍摄的。设置你的方向
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
或
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
如果您想稍后重新启用自动旋转功能,只需使用
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);