简体   繁体   中英

How can I lock my android app into portrait / landscape mode programatically?

I came up with a problem right now when my game is almost finish. The problem is that I want the player to be able to play both in landscape mode and portrait. How the player change mode is simple. Before he start the game, a message comes up and lets him decide witch mode he wants to play. Here comes the problem. In the Manifest.xml file - you can tell the game to play on just portrait or just landscape mode. So I wanna use a boolean to show witch one of the modes the player chose. But in xml, there is no "if" that can change the game depence the players choise. So how do I do to change the mode to the that one that the player choose?

Just use context.setRequestedOrientation() and place your xml inside the layout-land or layout-port folder.

Android will automatically choose the right layout depending on parameter SCREEN_ORIENTATION_LANDSCAPE or SCREEN_ORIENTATION_PORTRAIT

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