gcb
gcb

Reputation: 14548

How to get 1:1 pixels on android emulator?

I created an AVD without screen scaling, but the pixels do not match my screen.

is there any work around for this?

enter image description here

Screen is configured as 720 wide, but shows as 413 on my screen.

Edit: a little more experiementation, motivated by @Fallenreaper answer:

If I load a 500px wide image in the browser, it's still larger than the screen (which was supposed to be 720px wide).

enter image description here

Here is the 500px image, with two screen shots, scrolled to the right to show it's larger than the 720px screen.

edit 2: this may be related to this http://www.quirksmode.org/blog/archives/2010/04/a_pixel_is_not.html

Upvotes: 5

Views: 4788

Answers (2)

Heath Borders
Heath Borders

Reputation: 32117

When you start the emulator from Android Virtual Device Manager, you must check Scale display to real size, and then specify Screen Size (in) and Monitor dpi that calculates to a Scale value of 1.0 (or 0.50 if you're on a retina display on OSX).

In my case, I specified a 4.7 in Screen Size and a 160 Monitor dpi, which yielded a 0.50 Scale. When I take a screenshot of my emulator, it is now pixel-for-pixel what I would expect to see on the device.

You can also specify a command-line option -scale 1.0 when starting the emulator from the command-line.

If your emulator is already running, you can adjust the scale with the emulator console by sending window scale 1.0. This renders too large for me to use on my Retina MBP.

Discover your running emulators with adb devices. You should see output like this:

$ adb devices
List of devices attached 
emulator-5554   device

Then, you can connect to the device and send the scale command:

$ telnet localhost 5554
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
OK
window scale .50
OK
^]
telnet> quit
Connection closed.

And you can do it in a script with netcat:

$ echo 'window scale 0.50' | nc localhost 5554

Upvotes: 4

Fallenreaper
Fallenreaper

Reputation: 10694

each device has a different pixel density, so if you want to adjust it to be a 1-to-1 ratio, you will need to determine the devices pixel density, and compare with that of your host machine... then scale accordingly.

The different pixel densitieswill cause 1 to be bigger then the other, so if you are designing a screen, your textboxes would look right, being like 30x 150, but on the device, 30x150 would be far smaller.

Source: I do iOS and Android Web App Dev for WebViews and i have ran along this because i do it every day.

Upvotes: 0

Related Questions