Search code examples
androidnine-patch

Android: nine-patch is centered on one device, but moves somewhat to the right on another


I have a nine-patch image I put on a the background of a full-screen view:

enter image description hereenter image description here

And it looks as I want it on 800x480 and 1280x720 screens: it is has some equal transparent space on left and right sides. But on the FullHD screen the clear space on the left side is twice bigger than the space on the right side. But I have only one black pixel on both sides, so the clear spaces should be equal.

Then I modified my image like this:

originalscaled one

And now it looks centered on FullHD screen, but moved to the right on 800x480. How can I make it look centered on all the devices?

Now first image looks like this on FullHD device (this is the bottom part of the view):

enter image description here

and the second:

enter image description here

and they look vice-versa on 800x480 device.

The layout is as simple as this:

    ImageView ib = new ImageView(this);
    ib.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    ib.setBackgroundResource(R.drawable.scroll_both_ver);
    setContentView(ib);

Upd: The solution was to provide a copy in each of drawable-* folders.


Solution

  • Your 9 patch top center black area is not centered well, it has more space on the right than on the left. Not sure how this can explain your problem, but try to adjust it