How to create crisp background image for 1x1 Android widget?

前端 未结 1 625
借酒劲吻你
借酒劲吻你 2021-01-30 09:42

I\'m creating an a 1x1 widget, and no matter what I try, I just can\'t get the background image looking nice and crisp. I\'ve read just about any resource I can find, yet I sti

相关标签:
1条回答
  • 2021-01-30 10:10

    You may want to have a look at Google's Supporting Multiple Screen Sizes document. Basically what is happening here is that the screens on Android devices have different pixel densities. These are categorized as low, medium, high (ldpi, mdpi, hdpi). If an asset isn't large enough for a larger density screen, it is blown up to the proper size - this is probably what is happening to you.

    The Nexus One has a DPI somewhere around 250 which puts it into the hdpi class. Using the google formula of (number of cells * 74) - 2 to calculate dp for your 1x1 widget would make the widget dimensions 72x72 dp.

    The conversion from dp to pixels is:

    pixels = dp * (density / 160)
    

    So for a 72x72 dp image, the corresponding image sizes based on density would be:

    ldpi  (120 DPI) = 72 * (120 / 160) == 54 x 54 pixels
    mdpi  (160 DPI) = 72 * (160 / 160) == 72 x 72 pixels
    hdpi  (240 DPI) = 72 * (240 / 160) == 108 x 108 pixels
    xhdpi (320 DPI) = 72 * (320 / 160) == 144 x 144 pixels
    

    Use these formulas to create your assets and you should get crisp images.

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