how to know which phone support which layout(hdpi , mdpi and xhpi)?

前端 未结 2 1342
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 02:15

I\'m a little confused about how to determine which phones support what layout types. I\'ve done some research but haven\'t found a satisfying answer.

For example, I

相关标签:
2条回答
  • 2020-12-16 02:53

    Android treats mdpi (160 pixels/inch) as the base density. So for mdpi devices, 1 dp = 1 pixel. At higher densities, there are more pixels per inch (240 for hdpi, 320 for xhdpi).

    AutoMatic Scaling by Android itself:

    Android attempts to make graphic images occupy the same physical dimensions on the screen regardless of the device pixel density. So if all it finds is an mdpi resource, and the device is hdpi, it will scale the graphic by 240/160 = 150%, and it will double the size of the graphic for xhdpi.

    Using different versions of graphics :

    If you don't want this automatic scaling (which can make graphics look poor), you can simply supply your own version of graphic resources for use at higher densities. These graphics should be of the same size that Android would scale an mdpi resource.

    Note : the pixels/inch that was stored in the image file has nothing to do with this. It's all based on where you put the graphics files in the resources directory for your project. Any graphics placed in res/drawable are assumed to be properly sized for mdpi displays, as are graphics placed in res/drawable-mdpi. Image files that it finds in res/drawable-hdpi are assumed to be properly sized for hdpi displays, etc. When your program runs on a particular device, Android will first look for a graphic that matches the display density of that device. If it does not find one but instead finds one for a different density, it will use that and automatically scale the image based on the above rules.

    As the ldpi, mdpi and hdpi refer to screen density, which means how much pixels can fit into a single inch.

    the ratio in pixels between them is:

    ldpi = 1:0.75
    mdpi = 1:1
    hdpi = 1:1.5
    xhdpi = 1:2
    xxhdpi = 1:3
    

    so lets take an image with about the size of 100X100:

    for mdpi it should be 100X100
    for ldpi it should be 75X75
    for hdpi it should be 150X150
    for xhdpi it should be 200X200
    for xxhdpi it should be 300X300
    

    this way, for screens with the same size but different DPI, all the images seem the same size on screen.

    0 讨论(0)
  • 2020-12-16 02:57

    look into these details: android manages all this by itself, you just have to provide layouts and images in relative folders

    res/layout/my_layout.xml             // layout for normal screen size ("default")
    res/layout-small/my_layout.xml       // layout for small screen size
    res/layout-large/my_layout.xml       // layout for large screen size
    res/layout-xlarge/my_layout.xml      // layout for extra large screen size
    res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
    
    res/drawable-mdpi/my_icon.png        // bitmap for medium density
    res/drawable-hdpi/my_icon.png        // bitmap for high density
    res/drawable-xhdpi/my_icon.png       // bitmap for extra high density
    
    0 讨论(0)
提交回复
热议问题