Density in AVD manager

hackhack

Active Member
Licensed User
Longtime User
When you make a new virtual device you have to enter a density - how important is that? And how do you figure out what it is?
 

hackhack

Active Member
Licensed User
Longtime User
The density is very important. Device resolution is made of Height, width and density (or scale).
See this page for common values. Note that the resolution should be 120 (scale = 0.75), 160 (scale = 1.0) , 240 (scale = 1.5) or 320 (scale = 2.0). Not any other value.

Did you forget to include a link to a page?

This is my biggest conceptual problem - I don't comprehend this at all.
I'm not sure what density means, to me it would be how closely the pixles are in the display and that would affect how it looks to a human, but not the actual drawing of the graphics?

My HTC Desire has 480×800 so to me that would be the only thing mattering - except you say density is important *sigh* :sign0085:
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
My HTC Desire has 480×800 so to me that would be the only thing mattering - except you say density is important *sigh*

Density is simply a function of device size and resolution. If you had a device that was 1"x1" and a resolution of 240x240, then its density would be 240 dpi (dots per inch), which is referred to as a density of 1.5 based on a "standard" density of 160 dpi.

If you created a layout on that device and then ran it on a device that was 1"x1" with a resolution of 160x160 (denisty of 1), then your 240x240 layout wouldn't fit on it (obviously) without some adjustment.

If you are writing an app just for your own use, then density doesn't matter (assuming you got the layout working on your device). What's written at the link that I posted is aimed at people developing apps for distribution to others, in which case you must make adjustments to have the app run on devices of all different sizes and resolution.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Density is simply a function of device size and resolution.

'does not compute' "a function?" :BangHead:

If you had a device that was 1"x1" and a resolution of 240x240, then its density would be 240 dpi (dots per inch), which is referred to as a density of 1.5 based on a "standard" density of 160 dpi.

If you created a layout on that device and then ran it on a device that was 1"x1" with a resolution of 160x160 (denisty of 1), then your 240x240 layout wouldn't fit on it (obviously) without some adjustment.

Yeah, still don't get - different resolutions yield different amounts of space - sure. Get that. But I don't understand why we have to talk about density.

If you are writing an app just for your own use, then density doesn't matter (assuming you got the layout working on your device). What's written at the link that I posted is aimed at people developing apps for distribution to others, in which case you must make adjustments to have the app run on devices of all different sizes and resolution.

Yeah, I have a phone and tablet - but it would be nice if it would generally work everywhere.
Perhaps I can just avoid the designer and calculate positions of buttons and everything and set it at run time.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
There are lots of explanations in the documentation we suggested you.
What exactly do you not understand ?

Well, as i've said I don't understand why density matters (and how to calculate) - I only see how resolution matters.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You don't calculate the density, it is a property of the device and is determined by the device manufacturer. It sorts of corresponds to the dots per inch of the display. A font size that renders 12 pixels high on a density 1 device will render 18 pixels high on a density 1.5 device.

A layout will look the same on a 320 x 480 density 1 device as on a 480 x 720 density 1.5 device but the latter will look better because of the increased resolution.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The density is the number of pixels per inch.
You could have two different devices with the same resolution for example 640*960 pixels but with different physical sizes, a 3.5'' and a 7'' screen.
The device with the 3.5'' screen has a density of 320 pixels/inch
and the tablet with the 7'' screen has a density of 160 pixels/inch.
If you design one layout file for both you will get all views shown proportional to the physical screen size, a same button will have its physical width and hight double on the 7'' screen than on the 3.5'' screen.

In case above I would make two different layout files because the big physical difference. You can put much more views, with a same physical dimensions, on a 7'' tablet screen than on a 3.5'' screen with the higher density.
So one layout file with 640*960 density 320 for the 3.5'' screen
and a second one withe 640*960 density 160 for the 7'' screen.

Best regards.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
You don't calculate the density, it is a property of the device and is determined by the device manufacturer.

Thank you, brief and factual. Now i know that at least. Density can't be calculated, I have to look it.
So now i have to look up my phone to figure out what its density is.

It sorts of corresponds to the dots per inch of the display. A font size that renders 12 pixels high on a density 1 device will render 18 pixels high on a density 1.5 device.


So you took 12 and multiplied it by 1.5?

A layout will look the same on a 320 x 480 density 1 device as on a 480 x 720 density 1.5 device but the latter will look better because of the increased resolution.

So you multiply the base density value with width and height to get new values for other densitys?
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
The density is the number of pixels per inch.
You could have two different devices with the same resolution for example 640*960 pixels but with different physical sizes, a 3.5'' and a 7'' screen.
The device with the 3.5'' screen has a density of 320 pixels/inch
and the tablet with the 7'' screen has a density of 160 pixels/inch.
If you design one layout file for both you will get all views shown proportional to the physical screen size, a same button will have its physical width and hight double on the 7'' screen than on the 3.5'' screen.

In case above I would make two different layout files because the big physical difference. You can put much more views, with a same physical dimensions, on a 7'' tablet screen than on a 3.5'' screen with the higher density.
So one layout file with 640*960 density 320 for the 3.5'' screen
and a second one withe 640*960 density 160 for the 7'' screen.

So if I would want to make a layout for 480×800 and for 1280x800 it would be better to make two different layout files?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
So you took 12 and multiplied it by 1.5?
Yes.

So you multiply the base density value with width and height to get new values for other densitys?
Yes, but the OS will do it for you. The only difference could be different width/height ratios as explained in chapter '5 Screen sizes and resolutions' in the Beginner's Guide.

So if I would want to make a layout for 480×800 and for 1280x800 it would be better to make two different layout files?
Yes. For two reasons:
- the physical size difference
- the different width/height ratios

Best regards.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Yes.

Yes. For two reasons:
- the physical size difference
- the different width/height ratios

Ok, but lets say I don't care about the look, I make a button in the default emulator - what if I just want that button to scale and look huge on a tablet 1280x800 ? Adding it as a variant (scale 1, 160 dpi ) doesn't work, it just runs as a button in the upper left corner.
 
Upvote 0
Top