Android Emulator
Display Rotation
Android Development
Emulator Troubleshooting
Programming Help

How do I rotate the Android emulator display?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

When developing applications for Android, it's often necessary to test them in various screen orientations. This mimics how an app would behave in a real device when a user rotates their device. The Android emulator, part of the Android SDK, allows developers to rotate the display to test these scenarios. This article will guide you through the methods of rotating the Android emulator display, explaining the technical details and providing examples.

Software Keyboard Method

Most Android emulators are controlled by keyboard shortcuts. To rotate the screen, you can use:

  • Ctrl + F12 on Windows and Linux.
  • Cmd + F12 on macOS.

This rotates the emulator display but does not change the device's "orientation" from portrait to landscape or vice versa until you tell the emulator to do so.

Emulator Toolbar Method

Another straightforward way to rotate the Android emulator is by using the toolbar that appears on the side of the emulator window:

  1. Locate the Rotate button—it resembles a circular arrow, typically situated on the right or left side bar of the emulator window.
  2. Click this button to rotate the screen. Each click rotates the screen by 90 degrees.

Command Line Method

For those who prefer working with command line tools, the Android emulator can also be rotated using adb commands:

  • First, ensure that your emulator is running and detected by adb. You can check connected devices using:
 
  adb devices
  • To rotate the screen, you need to change the orientation of the device using:
 
  adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1

The rotation values are as follows:

  • 0 — Portrait
  • 1 — Landscape
  • 2 — Reverse Portrait
  • 3 — Reverse Landscape

These commands essentially modify the system settings of the emulator to mimic physical rotation.

Emulator Configuration File

For automated setups or specific project configurations, you might want to start the emulator with a predefined orientation. You can specify the initial orientation in the AVD (Android Virtual Device) configuration file:

  • Locate your AVD configuration file. Typically, it is located in:
 
  [USER_HOME]/.android/avd/[AVD_NAME].avd/config.ini
  • Change or add the following lines according to the desired startup orientation:
 
  hw.initialOrientation=landscape

or

 
  hw.initialOrientation=portrait

This setting ensures that every time you start your emulator, it loads with the set orientation.

Table: Rotation Methods and Usage

MethodTool/CommandDescription
Software KeyboardCtrl + F12Rotate emulator using the keyboard shortcut.
Emulator ToolbarRotate buttonClick the rotate button present in the emulator GUI.
Command Lineadb shell commandApply rotation via the Android Debug Bridge commands.
Configuration Fileconfig.ini settingPredefine emulator orientation in its configuration.

Additional Details

  • Sensor Simulations: Modern Android emulators can simulate various sensors. For orientation, this includes accelerometer and gyroscope, which can be tested by API calls within the app.
  • Graphics Performance: Rotation can affect the performance of your app, especially with graphic-intensive applications. Always test performance during and after rotations.
  • Testing Automation: During automated testing, such as with tools like Espresso or Appium, consider scripting the rotation events to ensure your app behaves correctly under different orientations.

Rotating the Android emulator display helps in thoroughly testing user interface and functionality to ensure the application is robust and delivers consistent performance under varying conditions. Each method mentioned has its own use case depending on the developer's environment and requirements.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.