Android listens to the vertical and horizontal rollover of the screen

  • 2020-05-19 05:50:01
  • OfStack

1, AndroidManifest. activity in xml


<activity
            android:name="com.suma.smartview.activity.LTVDetailActivity"
             android:configChanges="keyboardHidden|orientation|screenSize"/>
        <activity>

2. In the code

public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Switch to portrait 
if (newConfig.orientation == this.getResources().getConfiguration().ORIENTATION_PORTRAIT) {

} 
// Switch to landscape 
else if (newConfig.orientation == this.getResources().getConfiguration().ORIENTATION_LANDSCAPE) {
}


Related articles: