Android:在“活动"启动时获取方向(横向/纵向) [英] Android: Getting orientation (landscape/portrait) on Activity launch

查看:74
本文介绍了Android:在“活动"启动时获取方向(横向/纵向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的活动需要监视设备的方向.现在,这可以很好地与 onConfigurationChanged()一起使用,但是我还需要知道Activity启动时的方向.

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

这篇关于Android:在“活动"启动时获取方向(横向/纵向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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