用代码旋转屏幕
代码
1 btnRotate.setOnClickListener(new OnClickListener() {
2 @Override
3 public void onClick(View v) {
4 int r = Math.abs(getRequestedOrientation());
5 Log.d("DEBUG",Integer.toString(r));
6 Log.d("DEBUG","LANDSCAPE =" + Integer.toString(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE));
7 Log.d("DEBUG","PORTRAIT =" + Integer.toString(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT));
8 if (r == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
9 Log.d("DEBUG", "To " + Integer.toString(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT));
10 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
11 } else if (r == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
12 Log.d("DEBUG", "To " + Integer.toString(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE));
13 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
14 }
15 }
16 });
2 @Override
3 public void onClick(View v) {
4 int r = Math.abs(getRequestedOrientation());
5 Log.d("DEBUG",Integer.toString(r));
6 Log.d("DEBUG","LANDSCAPE =" + Integer.toString(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE));
7 Log.d("DEBUG","PORTRAIT =" + Integer.toString(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT));
8 if (r == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
9 Log.d("DEBUG", "To " + Integer.toString(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT));
10 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
11 } else if (r == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
12 Log.d("DEBUG", "To " + Integer.toString(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE));
13 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
14 }
15 }
16 });