Home » Android » How to get Android Studio to properly display dpi in preview?

How to get Android Studio to properly display dpi in preview?

Posted by: admin November 1, 2017 Leave a comment

Questions:

Short version: Is there a method whereby Android Studio will correctly preview a 1.33 density display? Choosing the virtual device I have defined from the preview window’s dropdown menu, a device which renders properly as 1.33 in the emulator, does not work.



I have a virtual device defined with a 1.33 density (by editing the device’s config file since I have not found any other method) which works fine in the emulator. However, the xml preview window continues to render the screen as mdpi, meaning that a 100px wide and a 100dp wide object render at the same size which is wrong for 1.33 density and unhelpful for layouts.

The hardware profile in AVD reports mdpi rather than 213dpi for this device even though the emulator works properly.

Cloning any of the virtual Nexus/Pixel hardware with a density specified in dpi results in the cloned hardware having a density specified as mdpi, hdpi etc. rather than the expected dpi from the parent. The parents will render px and dp in preview properly so evidently Android Studio is capable of displaying resolutions in preview outside of the standard 0.75, 1.0, 1.5,… bins. However, a cloned 5X does not keep its parent’s 420dpi density.

I found some old information that apparently worked several years ago but android studio no longer has the interface described and that I had to use a text editor to change the VM’s density rather than the AVD manager does not bode well.

Answers: