【问题标题】:Android Screen rotation, ACCELEROMETER_ROTATIONAndroid 屏幕旋转,ACCELEROMETER_ROTATION
【发布时间】: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


【解决方案1】:

将此代码添加到主活动的onCreate 中:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
  }

【讨论】:

    【解决方案2】:

    您可以在 AndroidManifest 中将此属性添加到您的活动中:

    android:screenOrientation="landscape"
    

    您可以找到有关 Android 活动属性here 的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-28
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多