How to emulate immersive mode in layout editor

删除回忆录丶 提交于 2019-12-05 22:41:58

Unfortunately seems there's no way of doing this. Such a basic feature should have been added long ago, IMHO this has higher priority than the fancy things we're shown at Google IOs. But anyway the layout editor usually breaks or throws exceptions. I'm not sure if this happens only in eclipse, as I'm not using Android Studio yet.

Workarounds

  • Test in simulator. Slower, and not an option if you are emulating large screens in a CPU without Intel VT-x extensions (Those using Macs are lucky)
  • As there's no way of getting rid of the black bar in the layout editor, you can create a new virtual device definition with the extra screen space required to accomodate the bar, so that the free screen area has the exact size of the device you need to emulate.

Example:
to emulate a 5 inch HD screen we would have created this device definition:

  • Screen size (in): 5.0
  • Resolution (px): 1920 x 1080

If we create an AVD with this definition and preview it in the layout editor in landscape mode, we'll see the dreaded black bar in the right side, which is eating up screen space and prevents correct visualization of views whose width is gravity dependent. To be able to view a free area of 1920x1080px, we can make a screen capture and measure with an image editor how much width is the black bar taking. In my case it was a 6.22%, so to have 1920px free width we need about 120 extra px, that sums a total of 2040px.

We now know our device must be 2040x1080, and we can use the Pythagorean theorem to calculate the diagonal in inches. In our example the new device definition would be:

  • Screen size (in): 5.24
  • Resolution (px): 2040 x 1080

This gives us a free area whose proportions are w/h=1.77, which is roughly 16:9.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!