Which folder to put 9png images to?
Asked Answered
B

3

20

We use 9png mainly to reduce the size of the apk. But, I am facing a peculiar problem. I am not sure in which folder I have to place the 9pngs in. I had put them in HDPI folder. Since Android is 'clever' it looks like if I use the app in an MDPI phone, it 'scales' the 9png which creates crazy effects. I didn't face any major problem until I tried it in Galaxy note. Looks like the 9png was taken from HDPI and scaled (Note has 800x1280) and it created weird effects.

  • So which is the right place to put the 9pngs?
  • How to tell Android system not to 'scale' 9pngs based on the folder it is put in?
Bybee answered 3/5, 2012 at 9:22 Comment(0)
E
15

According to Romain Guy's answer on Google groups:

The behavior of 9-patch is undefined when shrunk. In practice you will see overlaps of the various sections of the 9patch. Don't do it :)

From what I noticed in my projects, a 9PNG is scaled down just like any regular PNG, so I am usually requesting to our designer the entire set of images for ldpi, mdpi, hdpi and xhdpi, and I transform them all in 9patches.

That, unless there is a very simple 9patch, like a plain button background, that makes no difference when stretched or shrunk, so I usually place it in the regular drawable folder.

Evelinaeveline answered 3/5, 2012 at 10:40 Comment(0)
I
11

I had a similar problem with a nine patch image: if I placed it in the res/drawable folder, it didn't work on an ldpi screen (it distorted the image and lost the transparency).

The solution for me was to put it in the res/drawable-nodpi folder. The documentation states:

This can be used for bitmap resources that you do not want to be scaled to match the device density.

Ideologist answered 16/5, 2012 at 15:41 Comment(1)
This works for assets that don't contain any density-dependent features such as rounded corners.Thiosinamine
H
0

Just put the 9png in your HDPI folder.

if the effect looks weird in your Galaxy Note.

Ask the designer to give you a new 9png file for the XHDPI. and then put the new file in folder XHDPI.

Henleigh answered 3/5, 2012 at 9:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.