How do I prepare images for all the Android resolutions?

前端 未结 4 707
别跟我提以往
别跟我提以往 2020-12-23 11:43

In iOS preparing graphics is simple. There are either a normal image (height x width) or a retina image which is @2x (2 times height x 2 times width).

However, sin

相关标签:
4条回答
  • 2020-12-23 12:19

    On Android we usually handle image sizes in units of "dp" or "dip" which stands for device independent pixel. 1 dip = 1 pixel, on a mdpi screen. There are loads of devices out there with different screen densities, not just normal and retina, so there are multiple DPI buckets a device's screen may fall into:

    • ldpi (low dpi): around 120 dpi
    • mdpi (medium dpi): around 160 dpi
    • hdpi (high dpi): around 240 dpi
    • xhdpi (xtra high dpi): around 320 dpi

    Note that these are buckets, so a device with a 170 dpi screen will count as an mdpi device.

    Let's say that you have a vector based image in PS and you need to create an image resource for Android and you'd like to support all these screen densities. Let's say that image needs to be 100x100 dip large. So you create a 100x100 pixel version for mdpi, a 150x150 pixel version for hdpi, 200x200 for xhdpi, and 75x75 for ldpi. You can think of "mdpi - xhdpi" on Android as "normal - retina" on iOS.

    As for the larges image size that you can use, I really can't say. There's no hard limit as far as I know, but the device obviously won't be able to load a 20000x20000 bitmap into memory without downsampling because of heap limits.

    0 讨论(0)
  • 2020-12-23 12:21

    i got this off of this site a while back, it still comes in handy

    xlarge screens are at least 960dp x 720dp
    large screens are at least 640dp x 480dp
    normal screens are at least 470dp x 320dp
    small screens are at least 426dp x 320dp
    Generalised Dpi values for screens:
    
    ldpi Resources for low-density (ldpi) screens (~120dpi)
    mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
    hdpi Resources for high-density (hdpi) screens (~240dpi).
    xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
    Therefore generalised size of your resources (assuming they are full screen):
    
    ldpi
    Vertical = 426 * 120 / 160 = 319.5px
    Horizontal = 320 * 120 / 160 = 240px
    mdpi
    Vertical = 470 * 160 / 160 = 470px
    Horizontal = 320 * 160 / 160 = 320px
    hdpi
    Vertical = 640 * 240 / 160 = 960px
    Horizontal = 480 * 240 / 160 = 720px
    xhdpi
    Vertical = 960 * 320 / 160 = 1920px
    Horizontal = 720 * 320 / 160 = 1440px
    
    px = dp*dpi/160
    
    0 讨论(0)
  • 2020-12-23 12:26

    There is an online tool for that Android Asset Studio And also there is File|New|Android Icon Set in Eclipse

    0 讨论(0)
  • 2020-12-23 12:44

    In Android Studio just go to File -> New -> Image Asset and create your images right out of the IDE.

    0 讨论(0)
提交回复
热议问题