How to reference image resources in Android Studio

Source: Internet
Author: User

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.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.