我怎样才能得到当前屏幕的方向? [英] How can I get the current screen orientation?

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

问题描述

我只是想设置一些标志时,我的方向是横向,这样,当活动重新在的onCreate(),我可以什么之间为纵向加载与横向切换。我已经有一个布局,土地XML正在处理我的布局。

 公共无效onConfigurationChanged(配置_newConfig){

        如果(_newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
            this.loadURLData = FALSE;
        }

        如果(_newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            this.loadURLData =真;
        }

        super.onConfigurationChanged(_newConfig);
    }
 

压倒一切onConfigurationChanged将prevent我的布局,土地XML加载在横向方向。

我只想得到我的设备中的onCreate当前方向()。我怎样才能得到呢?

解决方案

  Activity.getResources()。getConfiguration()。方向
 

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);
    }

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

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天全站免登陆