安卓入门orienation(横向/纵向)上的活动启动 [英] Android: Getting orienation (landscape/portrait) on Activity launch

查看:282
本文介绍了安卓入门orienation(横向/纵向)上的活动启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的动态需要监视设备的方位。现在,这个工作原理与 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);
}                           

这篇关于安卓入门orienation(横向/纵向)上的活动启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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