Next, although this is useless for rotation, it does not mean it is useful. If an Activity is not specifically declared in onReusume, or is not in AndroidManifest. xml is configured as a horizontal or vertical screen. The declaration period during rotation is onCreate ------ onStart --- onResume --- screen rotation ---- onPause (Focus-removing) ---- onStop (invisible) --- onDestory, and then repeat onCreate --- onStart ---- onResume again. To do this, you need to set the screen to landscape or landscape. There are three methods:
1. Set in AndroidManifest. xml,
Android: name = "org. yanzi. testrotateimageview. MainActivity"
Android: label = "@ string/app_name"
Android: screenOrientation = "portrait"
>
2. In onResume
If (getRequestedOrientation ()! = ActivityInfo. SCREEN_ORIENTATION_PORTRAIT ){
SetRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_PORTRAIT );
}
Super. onResume ();
This method is strongly not recommended. Who knows it? It will slow down when the app is started in different directions!
3. In onConfigurationChanged, the following conditions are required for onConfigurationChanged to be valid in the listener screen direction:
A. add permissions to AndroidManifest. xml:
B. The MiniSdkVersion and TargetSdkVersion attributes set in AndroidManifest. xml are greater than or equal to 13.
C. Add the following in AndroidManifest. xml Activity:
Android: configChanges = "keyboard | screenSize | orientation | layoutDirection"
After the above, we can detect the screen direction change event in onConfigurationChanged (). Once the direction is set in AndroidManifest. xml, this part will become invalid. NewConfig. orientation = 1 indicates a portrait screen, and 2 is a landscape screen. Determine this and then setRequestedOrientation () to set the landscape or landscape.
This onConfigurationChanged ()-related configuration has the biggest advantage of not performing onPause onStop when the Activity direction changes... If you want to use setRequestOrientation to set a horizontal or vertical screen, the negative effect will be the same as that of the 2nd method, which is slow to death.
In short, the direction is still in the configuration !!! If you want to rotate the image, you can use RotateImageView andRotating LayoutThis layout allows the child controls in it to rotate without affecting the lifecycle of the parent layout and Activity.
For more information, see link 1 link 2 link 3