【发布时间】:2016-08-15 09:10:28
【问题描述】:
我试图让我的 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;
}
`
【问题讨论】:
-
试试this
-
Activity 在 Android 中默认旋转,因此您应该确保在您的设备中启用了 自动旋转 选项。
标签: android accelerometer screen-rotation