Android - Screen Resolution and Screen Density

2019-05-04 15:07发布

问题:

As per managing resources(images) in > Android 1.6 version, we need to keep different-resolutions image in Drawable-Hdpi, Drawable-Mdpi, Drawable-Lpi folder particularly.

And as per this page: http://developer.android.com/guide/practices/screens_support.html ,

In Low density section - there are three resolutions used: 240*320 , 240x400 , 240x432 for the Small screen, Normal Screen, Large Screen particularly.

same way for Medium density section - there are three resolutions used: 320x480 , 480x800 , 480x854 for the Small screen, Normal Screen, Large Screen particularly.

and same way for High density ........

but i am confused here:

(1) How do i come to know that whether small, Normal or Large screen is used, i mean is there any way to know ?

(2) How do i come to know which type of density i am using ?

(3) And in Drawable-Hdpi, Drawable-Mdpi, Drawable-ldpi folder, which resolution's image we should keep particularly?

pls share your knowledge.

回答1:

There are specific Android API calls that can, at runtime tell you what density and (small/large/normal) screen size a handset has. However, as a developer we should not need to worry about individual handsets at all. All we need to do is to have ldpi/mdpi/hdpi assets and small/normal/large layouts in the apk. Android internally handles everything.

Dont forget to get an indepth understanding of how Android determines which assets to use and aliasing here.



回答2:

Why do you want to know the actual density? It's Android's business. But I'm sure there is a way to retrieve this information.

For development I put everything in the hdpi-folder. I also could put everything in a general Drawable Folder.

At the time u publish u can decide if u want to provide already downscaled resources for ldpi and mdpi. However, thats not necessary.

Update: Retrieve actual density with this class and best practices

Update 2: I found a 25 min video from Motorola discussing all those issues: Working with multiple screens



回答3:

1) Change the content of the layout in different folders i.e layout-small, layout-large, etc Now test it in Different emulator with different screen resolution.

2) For Finding out density of the Device use
Log.d("Density", "" + (getResources().getDisplayMetrics().density));