During Game Development, some games can only be played on horizontal screens, so when mobile phones are erected,
Make sure that the game screen remains landscape. It is actually very easy to achieve this requirement,
Configure androidmanifest. xml. Add this line to Android: screenorientation = "Landscape ".
But the problem is that this will cause the activity to restart. Therefore, you need to save the status of the current activity before the activity is destroyed,
Load the configuration when the activity creates again, so that the ongoing game will not automatically restart!
However, a better solution is to add the Android: configchanges = "keyboardhidden | orientation" attribute to the corresponding activity, so that the activity will not be restarted. instead, call onconfigurationchanged (configuration newconfig ). in this way, you can adjust the display mode in this method.
For example
JavaCode
If (newconfig. Orientation = configuration. orientation_landscape ){
// Horizontal
Setcontentview (R. layout. file_list_landscape );
} Else {
// Vertical
Setcontentview (R. layout. file_list );
}
Android: configchanges = "keyboardhidden | orientation" can be added directly without additional code.