When developing an application using Android Studio, you must learn how to reference image resources, but because of Eclipse and Android Studio

There are differences in how to reference image files, so many new to Android Studio are confused about how to reference images

I’ll explain how to reference images in Android Studio next.

(1) It is better to use “.png “as the image in PNG format has smooth color transition and supports transparency

② The best name of the picture is non-number. This is because numeric images can cause errors when used in non-XML files, i.e., Java files.

Best solution: In Eclipse, place a PNG or.jpg image in a drawable folder, such as drawable-hdpi,drawable-ldpi,

drawable-mdpi,drawable-xhdpi,drawable-xxhdpi. The same image in a different drawable folder will display

It’s different. Android: SRC =”@drawable/ PIC “or Android :background=”@drawable/ PIC”.

\

In Android Studio, however, there are not so many drawable directories, but only one drawable folder. Take the generation

What is more, there are many MiPmap folders, such as Mipmap-hdPI, Mipmap-MDPI, Mipmap-xhdPI, mipmap-xxhdPI. As shown in the figure:

\

On Android, images in Drawable and MiPMap look the same, but why distinguish between the two files in Android Studio?

The official explanation is performance optimization, small memory footprint, etc.

Images are referenced in both files in a very similar way, using “@” in an XML configuration file. So this is also very simple, different pixels

Mipmap folder images are all used the same. But note: in AS, the same image is placed in the Drawable folder and the Mipmap folder

The following display effect is not the same, in size, zoom, pixel may be different, you can write an example to try.

\