1
我有一个FragmentActivity与其中的一些片段。当我从我正在拍摄的片段(片段A)中,将手机放在肖像位置,到我在代码setOrientation()中设置的下一个片段(片段B)到横向时,我握住黑色屏幕在将手机变为风景之前,纵向显示的手机和布局不会显示在第二个片段上。我的印象是,无论你如何拿着手机,当你做setRequestedOrientation()应该有力地表明您提供使用setRequestedOrientation时获得黑屏()
视觉布局:
----------- -----------
| | | | ---------------
| | | | | |
| Frag A | -> | Frag B | -> Until I turn -> | Frag B |
| |(then to)| (black) | it to Landscape | (not black |
| | | | | anymore) |
| | | | ---------------
----------- -----------
代码:
MainActivity这持有的方向变化:
// Set Orientation of the Activity.
public void setOrientation(int sensor) {
if (sensor == 1) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
} else if (sensor == 2) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
} else if (sensor == 3) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
} else if (sensor == 4) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else if (sensor == 5) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
弗拉加:
个@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Set the orientation to be in portrait and landscape.
((MainActivity) getActivity()).setOrientation(1);
...
}
FragB:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Set the orientation to be in landscape.
((MainActivity) getActivity()).setOrientation(5);
...
}