Android 屏幕旋转,ACCELEROMETER_ROTATION
Android Screen rotation, ACCELEROMETER_ROTATION
我正在尝试让我的 Android 应用程序在 运行 后立即旋转并修复旋转,我尝试了多种方法,例如:Settings.System.ACCELEROMETER_ROTATION它不会让它旋转,但它只是启用了旋转功能,我需要你的帮助提前谢谢你(^_^)。这是我的代码:
`
TableRow tableRow;
Time HourProgram;
RotateAnimation r;
int H = 12000, M = 1200;
int averageConsultationTime = 30;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
setAutoOrientationEnabled(this, true);
}
public static void setAutoOrientationEnabled(Context context,
boolean enabled) {
Log.i("OK", "setAutoOrientationEnabledOK");
Settings.System.putInt(context.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}
public static boolean getRotationScreenFromSettingsIsEnabled(Context context) {
int result = 0;
try {
result = Settings.System.getInt(context.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
return result == 1;
}
`
您只需将此属性添加到 AndroidManifest 中的 activity:
android:screenOrientation="landscape"
您可以找到有关 Android 活动属性的更多信息 here。
在主 onCreate
中添加此代码 Activity :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
我正在尝试让我的 Android 应用程序在 运行 后立即旋转并修复旋转,我尝试了多种方法,例如:Settings.System.ACCELEROMETER_ROTATION它不会让它旋转,但它只是启用了旋转功能,我需要你的帮助提前谢谢你(^_^)。这是我的代码:
`
TableRow tableRow;
Time HourProgram;
RotateAnimation r;
int H = 12000, M = 1200;
int averageConsultationTime = 30;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
setAutoOrientationEnabled(this, true);
}
public static void setAutoOrientationEnabled(Context context,
boolean enabled) {
Log.i("OK", "setAutoOrientationEnabledOK");
Settings.System.putInt(context.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}
public static boolean getRotationScreenFromSettingsIsEnabled(Context context) {
int result = 0;
try {
result = Settings.System.getInt(context.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
return result == 1;
}
`
您只需将此属性添加到 AndroidManifest 中的 activity:
android:screenOrientation="landscape"
您可以找到有关 Android 活动属性的更多信息 here。
在主 onCreate
中添加此代码 Activity :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}