Search code examples
androidbordernine-patch

Incorrect stretching of simple 9-patch image to get 1px border on high-res devices


I want to get a simple 1px border with white background as 9-patch for a view in android application. It works fine on the Samsung Galaxy Tab 730, but to my suprise, the result on Samsung Nexus 10 is completely different:

Desired result (1px blue border and white background): Info Window with 9-patch background correctly displayed.

Actual result (1px blue border and light blue background): Info Window with 9-patch background and blue background (incorrectly stretched)

The used 9-patch is very simple: used 9-patch image, enlarged: enter image description here


Solution

  • Two solutions I found worked for me:

    • Dirty hack: Replacing the image with the following slightly bigger image (that is not affected by rescaling on the larger screen device, but might be affected on even larger displays): 9-patch 1px border with 3x3px white , enlarged enter image description here
    • Correct solution: Moving the 9-patch image to the folder res/drawable-nodpi (see 9patch is stretching areas I didn't mark) to prevent it from being rescaled on any devices.