首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓屏幕旋转,ACCELEROMETER_ROTATION

安卓屏幕旋转,ACCELEROMETER_ROTATION
EN

Stack Overflow用户
提问于 2016-08-15 09:10:28
回答 1查看 1.2K关注 0票数 2

我正在尝试让我的Android应用程序在运行并修复旋转时立即旋转,我尝试了多种方法,比如:Settings.System.ACCELEROMETER_ROTATION --它不让它旋转,但是它只是启用了旋转功能,我需要您的帮助--提前感谢您(^_^)。这是我的代码:

`

代码语言:javascript
复制
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;
}

`

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-15 09:31:45

您只需将此属性添加到AndroidManifest中的活动中:

代码语言:javascript
复制
android:screenOrientation="landscape"

您可以找到更多关于Android活动属性这里的信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38952297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档