Android always monitors the Rotation Angle of the mobile phone. determines at which angle the vertical screen layout is loaded Based on the rotation angle.
I. Scenario Description:
During recent development, we encountered a problem that the operating system was aware of the horizontal and vertical screen layout when performing horizontal and vertical screen switching, as an developer, you cannot determine when the Activity loads the landscape layout and when the landscape layout is loaded. Therefore, in order to find the demarcation points for loading the horizontal and vertical screen la S, I have monitored the angle of screen rotation in particular, to see what angle will the horizontal screen la s, at what angle is the vertical screen layout loaded.
Ii. Change of screen Rotation Degree
The degree changes. The mobile phone rotates clockwise, And the degree increases.
3. Listen to the rotation angle of the mobile phone in the Activity and add the code.
/*** Check whether the screen direction changes from time to time * @ author wilson. xiong */class MyOrientationDetector extends OrientationEventListener {public MyOrientationDetector (Context context) {super (context) ;}@ Overridepublic void onOrientationChanged (int orientation) {// If the screen rotation is turned on, set the screen to be rotated // 0-57 degrees 125-236 degrees 306-360 degrees. These ranges are vertical screens. // The range of 58-124 degrees 237-305 degrees is landscape screen if (orientation =-1 | (orientation> = 0) & (orientation <= 57) | (orientation> = 125) & (orientation <= 236 )) | (orientation> = 306 & orientation <= 360) {mScreenOrientation = 1; // landscape} else if (orientation> = 58 & orientation <= 124) | (orientation >=237 & orientation <= 305) {mScreenOrientation = 0; // landscape screen} // mOrientation = orientation ;}}
Usage of this class:
(1) Call the enable () method in onResume () to listen for angle changes
@Overridepublic void onResume() {super.onResume();mDetector.enable();if (!isFirst) {if (GTConfig.instance().hasDickLoaded) {GTSQuote.updateGTSQuoteList();}refreshData();} else {isFirst = false;}}
(2) Call the disable () method in the onPause () method to stop listening.
@Overridepublic void onPause() {super.onPause();mDetector.disable();}