Search code examples
androidnine-patchandroid-4.2-jelly-beanandroid-drawable

Android 4.2 9-patch background drawn differently than older OS versions


I have a Nexus 7 with Android 4.2.1 and I noticed in my app the background image I am using for some linear layouts is drawn incorrectly. With other devices with older versions of the Android OS the 9-patch background is drawn correctly but with this device the border line is stretched when it should not be stretched.

Correct (Evo 4G v2.3.5): https://i.sstatic.net/xhKLt.png

Incorrect (N7 v4.2.1): https://i.sstatic.net/v70w1.png

Any idea what is causing this? If not, is there any other way to get the black borders on these views without using 9-patch images?

edit

9-patch file: https://i.sstatic.net/uIs74.png

9-patch in editor tool: https://i.sstatic.net/rJjUL.png

layout xml section using it (leftbordergraybkg):

<LinearLayout
 android:id="@+id/Measurements"
 android:layout_width="0px"
 android:layout_height="match_parent"
 android:layout_weight="50"
 android:background="@drawable/leftbordergraybkg"
 android:orientation="vertical">

Solution

  • It's because of black pixels showing scalable area are too close to image's border. That's why in higher pixel density 9-patch file scales up and scale piece of border.

    See example which will not have such problem.

    enter image description here