Usually our app will only be designed as a horizontal screen or vertical screen, the way to lock the horizontal screen or vertical screen is to set the attribute android:screenorientation "Landscape" or "portrait" in the Androidmanifest.xml file: < Activity android:name= "com.example.kata1.MainActivity" android:label= "@string/app_name" android:screenorientation= "Landscape" > <intent-filter> <action android:name= "Android . Intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> & Lt;/intent-filter> </activity> In fact Screenorientation can also be set to many values:
Android:screenorientation = ["Unspecified" | "Behind" |
"Landscape" | "Portrait" |
"Reverselandscape" | "Reverseportrait" |
"Sensorlandscape" | "Sensorportrait" |
"Userlandscape" | "Userportrait" |
"Sensor" | "Fullsensor" | "Nosensor" |
"User" | "Fulluser" | "Locked"]
Where Sensorlandscape is horizontal screen according to gravity upside down, sensorportrait vertical screen according to gravity upside down. If you are interested, you can also try other values oh ...