set 9 patch from assets folder

492 views Asked by At

How can I set imageView border from 9 patch file in assets folder? I have tried this but didn't work.

Drawable d = Drawable.createFromStream(getAssets().open("borders/border1.9.png"), null);
imageView.setBackground(d);

Any idea?

1

There are 1 answers

1
Marcos Vasconcelos On

9-Patch PNGs are compiled on build time.

Non compiled .9.PNG is a usual PNG and is loaded as is.

The build.xml describes the task to compile .9.pngs to the AAPT (Android Asset Packaging Tool).

You can't compile it on runtime, put you can precompile them with aapt:

 aapt.exe c -S <input-folder-with-images>  -C <outpout-folder>

Where: 'output-folder' has to exist