How to emulate immersive mode in layout editor

2019-05-15 13:15发布

问题:

I'd like to view my layouts in full screen in the layout editor. I'm using the eclipse plugin.

I've already hidden the ActionBar by selecting a *NoActionBar theme in the combo, but the navigation bar is a different story. AFAIK it can only be hidden using flags in code.

I need to make continuous tweaks in the activity xml files, and testing it in the emulator is a real pain, when not directly impossible (my PC can't run a full HD emulator, and I'd need to SSH another machine). Needless to say I dont have the real device.

Is there a way of viewing layouts in true full screen?

回答1:

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.