Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which folder to put 9png images to?

Tags:

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?
like image 883
Codevalley Avatar asked May 03 '12 09:05

Codevalley


People also ask

How to put image in Drawable XML file?

Step 1: In this method first of all in your system find your required images and copy the image as we do normally. Step 2: Then open the Android Studio go to the app > res > drawable > right-click > Paste as shown in the below figure. Step 3: Then a pop-up screen will arise like below.

What is the preferred image format for the drawables?

Supported file types are PNG (preferred), JPG (acceptable), and GIF (discouraged).

How to add image resource in Android studio?

To import image resources into your project, do the following: Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.


2 Answers

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.

like image 167
Adinia Avatar answered Oct 22 '22 01:10

Adinia


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.

like image 36
John Avatar answered Oct 22 '22 02:10

John