在Activity&Fragment複寫方法
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
//是否顯示在用戶手機上
if(isVisibleToUser) {
Activity a = getActivity();
if(a != null)
//旋轉成橫屏
a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//旋轉成豎屏
a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}