开发者

Android: Getting orientation (landscape/portrait) on Activity launch

开发者 https://www.devze.com 2023-01-13 05:21 出处:网络
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.

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.

开发者_如何学GoSo how do find out the current orientation of the device in my onCreate(), for instance?


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

精彩评论

暂无评论...
验证码 换一张
取 消