Search code examples
androidnine-patchdensity-independent-pixel

calculating nine patch sizes for all densities


I dont know how is best way to calculate size in pixels for round corners in nine patch images in all folders (hdpi, mdpi...), if I want for example 5dp round corner or something close to this size on all devices


Solution

  • Read up on this link

    A quick summary is

    ldpi (0.75 x mdpi)
     |
    mdpi (basline)
     |
    hdpi (1.5 x mdpi)
     |
    xhdpi (2.0 x mdpi)
    

    And also, remember that Android will scale the images, so if you set the corner as 5dp. It will be 5dp on all devices. Different res images are used to make sure it dosent look low quality on a higher density screen.

    So in your case, create a 5px image (mdpi one) then scale it to other densities using the metrics shown above.