我怎样才能得到当前屏幕的方向?屏幕、方向

2023-09-12 06:56:58 作者:将军与马

我只是想设置一些标志时,我的方向是横向,这样,当活动重新在的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()。方向
 

装企现在获客太高了,怎么才能降低成本 3个回答,你认同哪个

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