安卓入门orienation(横向/纵向)上的活动启动纵向、横向、入门、orienation

2023-09-05 10:36:06 作者:半世倾尘

我的动态需要监视设备的方位。现在,这个工作原理与 onConfigurationChanged(),但我还需要知道我的方向活动开始的时候。

My Activity needs to monitor the orientation of the device. Now this works great with onConfigurationChanged(), but I also need to know orientation when my Activity starts.

那么,如何找出设备的当前方位在我的的onCreate(),例如?

So how do find out the current orientation of the device in my onCreate(), for instance?

推荐答案

我不是专家,但这个工作对我来说,在的onCreate()

I'm no expert but this works for me, in onCreate():

int display_mode = getResources().getConfiguration().orientation;

if (display_mode == Configuration.ORIENTATION_PORTRAIT) {
    setContentView(R.layout.main);
} else {
    setContentView(R.layout.main_land);
}