Android Widget Bitmap Sizes

后端 未结 2 811
刺人心
刺人心 2021-02-02 18:04

Hallo,

I am writing a widget, but am unsure what size bitmap to use as a background for each screen resolution/density.

According to the Android Developer App Wi

相关标签:
2条回答
  • 2021-02-02 18:27

    You just need to convert 72dp x 294dp into actual pixel sizes for ldpi, mdpi, and hdpi. That process is explained here:

    http://developer.android.com/guide/practices/screens_support.html

    The formula is pixels = dps * (density / 160), so in your case, 72 dp x 294 dp would equal:

    • ldpi (120): 54 x 221 pixels
    • mdpi (160): 72 x 294 pixels
    • hdpi (240): 108 x 441 pixels
    • xhdpi (320): 144 x 588 pixels

    Update in response to your second update: Density-based resources are aimed at making sure that graphics are (roughly) the same actual size across devices. In your case, though, you don't care about the actual size, you care about the background filling up whatever space it is supposed to fill for the widget. You should be able to handle this issue for most backgrounds by created an Nine Patch image. The Nine Patch will scale according to the size required.

    http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

    http://developer.android.com/guide/developing/tools/draw9patch.html

    0 讨论(0)
  • 2021-02-02 18:33

    There is good advice from Google on icon sizes here: http://developer.android.com/guide/practices/ui_guidelines/icon_design.html

    I guess they should apply to custom widgets too.

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