How to reference image resources in Android Studio
With the constant access to Android Studio, it is increasingly found that there is a huge difference with Eclipse. Whether it is the directory structure on the surface or the internal management of various resources. This article will talk about how to display images in Android Studio and the differences with Eclipse.
In eclipse.jpg, the images are placed in the drawable folder, such as drawable-hdpi, drawable-ldpi, drawable-mdpi, drawable-xhdpi, and drawable-xxhdpi. the same image is placed in different drawable folders and displayed differently. But it is the same when referenced in xml: android: src = @ drawable/pic or android: background = @ drawable/pic.
But it is different in Android Studio. There are not so many drawable directories, but only one drawable folder. Instead, many mipmap folders are displayed, such as mipmap-hdpi, mipmap-mdpi, mipmap-xhdpi, and mipmap-xxhdpi .:
.
First try to put the image in drawable, and then use android: src = @ drawable/pic or android: background = @ drawable/pic in xml. use, found no problem, can be displayed completely. But why are there so many mipmaps?
Google's official explanation is performance optimization, memory usage, and so on (the concept of Baidu mipmap itself ..), In short, the form of mipmap is better than drawable. So, we recommend that you use mipmap in Android Studio. Well, we put the image under the mipmap folder. How can we use it in xml?
android:src=@mipmap/pic
It is similar to the reference method in which an image is placed in drawable. It is also referenced. Therefore, this is also very simple. The image in the mipmap folder of different pixels is used in the same way. However, note: In AS, the display effect of the same image in the drawable folder is different from that in the mipmap folder, and may vary in size, scaling, and pixels, you can write an example and try it by yourself. I will not give the texture here. Compared with Eclipse, Android Studio is similar and different.