[英]Android: Getting orientation (landscape/portrait) on Activity launch
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. 现在这对onConfigurationChanged()
非常onConfigurationChanged()
,但是当我的Activity开始时我也需要知道方向。
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()
: 我不是专家,但这对我onCreate()
,在onCreate()
:
int display_mode = getResources().getConfiguration().orientation;
if (display_mode == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.main);
} else {
setContentView(R.layout.main_land);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.