如何获得当前的屏幕方向? [英] How can I get the current screen orientation?

查看:26
本文介绍了如何获得当前的屏幕方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在我的方向为横向时设置一些标志,以便在 onCreate() 中重新创建活动时,我可以在纵向加载和横向加载之间切换.我已经有一个 layout-land xml 来处理我的布局.

I just want to set some flags when my orientation is in landscape so that when the activity is recreated in onCreate() i can toggle between what to load in portrait vs. landscape. I already have a layout-land xml that is handling my layout.

public void onConfigurationChanged(Configuration _newConfig) {

        if (_newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            this.loadURLData = false;
        }

        if (_newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            this.loadURLData = true;
        }

        super.onConfigurationChanged(_newConfig);
    }

覆盖 onConfigurationChanged 将阻止我的 layout-land xml 横向加载.

Over-riding onConfigurationChanged will prevent my layout-land xml from loading in landscape orientation.

我只想在 onCreate() 中获取设备的当前方向.我怎样才能得到这个?

I just want to get the current orientation of my device in onCreate(). How can I get this?

推荐答案

Activity.getResources().getConfiguration().orientation

这篇关于如何获得当前的屏幕方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆