Open the AndroidManifest.xml
file and set the screenOrientation
attribute to “landscape” for the activity you want to force horizontal orientation. For example:
<activity
android:name=".YourActivity"
android:screenOrientation="landscape">
</activity>
In the activity’s Java/Kotlin file, you can also programmatically enforce the landscape orientation by adding the following code in the onCreate()
method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_main);
}