18 Dec
Posted by support as General 2 views
Original From: http://blog.sina.com.cn/s/blog_4ca975460100g5yj.html
Android if they had to switch on the screen solution
The time in the development of the game, some games are only horizontal screen play, so when placed in the erection of mobile phone, to keep the game screen is still horizontal screen. To achieve this requirement is very simple to configure in the AndroidManifest.xml inside look on it. Add this line android: screenOrientation = "landscape".
For example, (landscape is a horizontal, portrait vertical):
Java code
<? xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns: android = "http://schemas.android.com/apk/res/android"
package = "com.ray.linkit"
android: versionCode = "1"
android: versionName = "1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android: name = ". Main"
android: label = "@ string / app_name"
android: screenOrientation = "portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</ intent-filter>
</ activity>
<activity android: name = ". GamePlay"
android: screenOrientation = "portrait"> </ activity>
<activity android: name = ". OptionView"
android: screenOrientation = "portrait"> </ activity>
</ application>
<uses-sdk android:minSdkVersion="3" />
</ manifest>
<? xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns: android = "http://schemas.android.com/apk/res/android"
package = "com.ray.linkit"
android: versionCode = "1"
android: versionName = "1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android: name = ". Main"
android: label = "@ string / app_name"
android: screenOrientation = "portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</ intent-filter>
</ activity>
<activity android: name = ". GamePlay"
android: screenOrientation = "portrait"> </ activity>
<activity android: name = ". OptionView"
android: screenOrientation = "portrait"> </ activity>
</ application>
<uses-sdk android:minSdkVersion="3" />
</ manifest>
In addition, android dynamic switching each time the screen will restart Activity, so it should be in the Activity prior to their destruction to save the state of current activity in the Activity, when re-Create load configuration, as carried out in the game will not be automatically restarted!
Reprinted from: http://rayleung.javaeye.com/blog/426972
Answers Time :2009-01-18 18:04
When the screen when the screen becomes horizontal, the system will re-calls the current Activity's OnCreate method, you can put on your OnCreate the following methods to check the current in the direction of, then you can let your SetContentView to load a different Layout xml.
if (this.getResources (). getConfiguration (). orientation == Configuration.ORIENTATION_LANDSCAPE) (
Log.i ( "info", "landscape");
)
else if (this.getResources (). getConfiguration (). orientation == Configuration.ORIENTATION_PORTRAIT) (
Log.i ( "info", "portrait");
)
When switching on the screen first need to add the configuration in the androidmanifest.xml
android: configChanges = "orientation | keyboardHidden | navigation
So in the program. Activity will not be repeated call onCreate ()
Does not even call onPause.onResume.
Will call a onConfigurationChanged (Configuration newConfig)
This is the XML configuration option to join the premise.
If you join the options on the premise. As stated above. Activity will be re-activated onCreate method
According to your own needs to choose the configuration changes when the mechanism for handling such a better life.
Tags: android, reproduced, screen, solution, switchPermalink: Code Library - Android if they had to switch screen solution (reproduced)
Subcribe the update with Google Reader.
RSS feed for comments on this post
Leave a reply