简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM