0

I have created an avd of Xiomi Redmi 3s (294dpi), whose specifications are:

enter image description here

enter image description here

The generalized densities in Android are:

  • Ldpi (low) ~ 120 dpi -> dp = px * 0.74
  • Mdpi (average) ~ 160 dpi -> dp = px * 1
  • Hdpi (high) ~ 240 dpi -> dp = px * 1.5
  • Xhdpi (extraalta) ~ 320 dpi -> dp = px * 2
  • Xxhdpi (extra extraalta) ~ 480 dpi -> dp = px * 3
  • Xxxhdpi (extra extra extraalta) ~ 640 dpi -> dp = px * 4

When I create the avd with device specifications, the assigned density is xhdpi (x2), but the actual device density factor is less than x2, as with most devices, so the preview result does not match the actual appearance of the device screen. For example, the same thing happens with the Nexus 5x, which has the resource density of xxhdpi (x3), but the actual density is 2.63

In Android Studio, emulated devices such as Nexus 5x or Pixel XL, specifies the special density of 420dpi and 560dpi respectively, where the density factor is 2.6 (xxhdpi) and 3.5 (xxxhdpi) approximately.

To determine the width dp and its density factor of the Xiomi Redmi 3S I have used:

dpi/160 = densityPxValue 294/160 = 1,8375

and I calculated the real density with https://stackoverflow.com/a/5104104/4114846

The result is the density of 294 dpi and the actual density factor is 1.83, but the resource folder assigned by the system is xhdpi (x2) and the preview corresponds to the generalized density.

How can I create an avd and preview by specifying the density of the device or its density factor so that it looks like the actual device ?

If you can not specify with android studio, what alternatives do we have?

Community
  • 1
  • 1
yeberiah
  • 214
  • 4
  • 12
  • Use an actual device. Attempting to mimic a specific Android device using an emulator is futile IMHO. Use the emulator for testing general scenarios. – CommonsWare Apr 30 '17 at 19:24
  • Thank you for answering so quickly. I can not have a real device. My need arises from a user report that can not see a screen well. There has to be some way to emulate the devices correctly. – yeberiah Apr 30 '17 at 19:37
  • Ask the user to send you screenshots. If your UI is that sensitive to small changes in density, you have *major* problems in the UI. You should be able to see those problems in a variety of emulators, plus whatever devices you have access to. Beyond that, use hosted app testing services that can give you screenshots. – CommonsWare Apr 30 '17 at 19:40

1 Answers1

6

Find your AVD folder.

C:\users\<user>\.android\avd

Open the folder for the device and edit line:

hw.lcd.density=320

in

config.ini

While you have calculated 294 ppi, 294 is not allowed. Allowed values are:

120, 160, 213, 240, 280, 320, 360, 400, 420, 480, 560, 640

Please note, that those are densities:

0.75, 1, 1.33, 1.5, ...

Please note that 1.33 does not fit the Android list of ldpi, mdpi, hdpi, ...

It was needed so there was a value between mdpi and hpdi. I suspect there was hardware which had 213 ppi displays but hardward specs routinely change. Phones today are getting bigger while keeping the same pixel count, so a 4.5", 213 ppi phone from a few years ago has been replaced by a 5", 196 ppi phone.

The hardware factory sets the logical density at whatever number they like but if sensible they set it as close to the physical density as possible. So, a device will be set at 213 even though it's really 196.

Unfortunately, this leads to problems like you have encountered. Since you say the physical screen size gives a resolution of 294 ppi it is likely the hardware was set at density 1.75 (280 ppi). This is 5% less than the physical ppi but it is common for devices to report logical densities that different to physical densities (for example, 213 is 8% larger than 196).

Because 280 is exactly half way between 240 hdpi and 320 xhdpi I don't know how it will scale views. The emulator may render your layout perfectly but it may be using drawables from the hdpi folder. Your client's hardware may select drawables from the xhdpi folder which will scale them very differently.

Smartybartfast
  • 161
  • 1
  • 6
  • @RussWheeler I got the emulator working precisely at the logical densities I wanted. If you mean you want an emulator to run at a logical density of 345, no one can do that in Studio and no Android hardware exists that runs at that density because Google has defined the allowed densities and 345 is not on the list. I suppose someone could write an emulator that runs at that density but since no hardware runs at it and I write for hardware not non-emulators I can't see any advantage in doing it. As my answer says, even if hardware had a particular physical density the manufacturer approximates. – Smartybartfast Feb 18 '18 at 14:21
  • Maybe I have a diff use case to you. I am using a gaming library called libGDX. In using that, I am not bound to the android bucket sizes, so my game looks different on each device. When I view my game on both a Nexus 6 and Nexus 6P they look different, because the dpi is diff on the devices. However, using an emulator it is impossible to create diff dpis as the emulator always rounds up/down to the nearest bucket. Does that make sense? – Russ Wheeler Feb 18 '18 at 14:29