Android multiple screen support
I am confused about android's multiple screen support. http://developer.android.com/guide/practices/screens_support.html I read this article, but still something is not clear for me.
- I used dp instead of px in my layout
- I put high, medium, low version's of an image to drawable directories.
I made this changes according to this article. But in some densities, there is still problem although some of them work very well.
The question is what is the exact width and height in开发者_如何学C dp units for variety of android screen types. if it is changeable, what is the difference between px?
- px is changeable, dp is changeable too??? what is the difference??
if changeable, should I change the view's width and height by code on Create function or create seperate layouts for each screen dentisies? Please give a way to understand this...
Thanks in advance..
px are not changeable. dps or dips are.
To calculate how many px your object specified in dps will be use the formula below:
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
px is a fixed measure. This means that if 100px on a small screen take up 1/2 of the screen, it will take up much less on a large screen. dp = density (independent) pixels, is based on the densitity of the device. So if you specify a width to 50dp on a small screen, it will expand on a large screen. Note that dp is not an insurance of layout compability on all devices, since devices have different aspect ratios. To build a perfect layout, that looks exactly the same on all devices, you must use more techniques. Linearlayout allows you to assign weights. Look into that. http://developerlife.com/tutorials/?p=312
精彩评论