Search code examples
androidandroid-studionine-patch

Android 9 Patch Not Scaling Correctly After Updating Android Studio


I was using a 9-patch image for a button in my program, when suddenly, after updating Android Studio from 2.1 preview 1 to 2.2 preview 3, as well as updating the build tools and platform tools, a couple of 9-patches stopped scaling correctly. Not all of them, only the ones displayed on-screen. Meaning that 9-patch 'B' scaled properly the first time I ran the app, but never after that. Similarly, even when 9-patches 'A' and 'B' were scaling incorrectly, 'C' worked properly the first time I opened its Activity, but the next time I did, it was wrong. By the end of my poking around, every last one of my 9-patches was scaling incorrectly, meaning they were scaling as if they were regular PNG files.

What I've tried: I have checked several times to ensure that all border pixels are either fully transparent or fully black opaque. I've ensured that I only have single line on the padding (right and bottom) sides of the image. I've re-exported the files from draw9patch (also tried from GIMP), and cleaned and re-built the project and re-imported all drawables several times. I even reverted to my old version of Android Studio.

Is this some sort of bug with the new SDK or build tools, or somehow Android Studio? Is it corrupting my 9-patches on the device at runtime? Has anyone ever had this problem?

I'll post the 9-patch just in case someone happens to want to double-check my work (These 9-patches have all been working for months up to now)

9-patch file:

9-patch resource

In editor (draw9patch):

enter image description here


Solution

  • The easier fix is to change the android plugin version to 2.1.0 instead of 2.2.0 until 2.2 is stable:

    classpath 'com.android.tools.build:gradle:2.1.0

    See answer Default pressed MenuItem with 9-patch border after Android Studio 2.2