How to change the screen size, density and orientation?
There are two kinds of display of your board: LCM via MIPI-DSI among the 60 pins high speed expansion connector, TV or LCD monitor via HDMI. No matter what you chose, it may need to change the resolution and density to fit your screen display.
Before we go ahead, there are some basic terms and concepts need to read through to help we better understand the parameters we will face.
- Screen size
- Actual physical size, measured as the screen's diagonal.
For simplicity, Android groups all actual screen sizes into four generalized sizes: small, normal, large, and extra-large.
- Screen density
- The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch). For example, a "low" density screen has fewer pixels within a given physical area, compared to a "normal" or "high" density screen.
For simplicity, Android groups all actual screen densities into six generalized densities: low, medium, high, extra-high, extra-extra-high, and extra-extra-extra-high.
- ldpi (low) ~120dpi
- mdpi (medium) ~160dpi
- hdpi (high) ~240dpi
- xhdpi (extra-high) ~320dpi
- xxhdpi (extra-extra-high) ~480dpi
- xxxhdpi (extra-extra-extra-high) ~640dpi
Illustration of how Android roughly maps actual sizes and densities to generalized sizes and densities (figures are not exact).
- The orientation of the screen from the user's point of view. This is either landscape or portrait, meaning that the screen's aspect ratio is either wide or tall, respectively. Be aware that not only do different devices operate in different orientations by default, but the orientation can change at runtime when the user rotates the device.
- The total number of physical pixels on a screen. When adding support for multiple screens, applications do not work directly with resolution; applications should be concerned only with screen size and density, as specified by the generalized size and density groups.
- Density-independent pixel (dp)
- A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple:
px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
OK, Let's move forward to change your board screen size, density and orientation:
Query the display parameters of your board
$ dumpsys display | grep DisplayInfo
The first line (mBaseDisplayInfo) is LCM display info details including resolution, density, rotation parameters;
The second line (mOverrideDisplayInfo) is HDMI display info details including resolution, density, rotation parameters.
Change your board screen size
$ wm size 1920x1080
Change your board density
The DPI you choose depends only on your personal preference. Android devices ship with DPIs ranging from 120 up to 640, but know that as you decrease the value, the icons and font size decrease as well.
$ wm density 240
Change your board orientation
When connect the board to HDMI TV or LCD Monitor, the default orientation is not good for user experience. Meanwhile, there is no built-in accelerometer on the board, you need to change the orientation manually to fit your display device.
First of all, turn off the automatic rotation:
$ content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
Rotate to landscape:
$ content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1
Rotate to portrait:
$ content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0
After above setting changes, we can find the difference on either screen display or the terminal output display. Here we can check it as below figure.