My app does the following:

  1. I take a picture
  2. The picture is displayed in a DialogFragment

If I take the picture in landscape mode, I want the orientation of the DialogFragment which is showing my image to be locked to landscape mode. If I take the image in portrait mode, I would like the orientation of the DialogFragment be locked to portrait mode.

Is that possible?

有帮助吗?

解决方案

Check the width and height of your image, that should be enough to tell you wether it was taken in portrait or landscape mode. Set your orientation with

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

or

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

And if you want to re-enable your auto-rotate functions at a later time just use

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top