Android Image Resource Processing

Source: Internet
Author: User

Android uses the picture resources generally refers to three kinds: png/jpg bitmap style,. 9 files, selector XML files, in the previous development, are placed in the drawable directory, but when using the latest Android studio, We will find that all the login icons are placed by default in the Mipmap directory, and different sizes of images are in different sub-directories. is not in the new version, all the bitmap resources are moved to the Mipmap directory, we go to the official development guide can be seen, drawable and mipmap directory use explained as follows:



In other words, other icon images,. 9 images, and XML files are still placed in the drawable directory, in addition to the icons used in the Mipmap directory.

However, I personally feel that the following methods are more convenient:

1). 9 files and XML files are placed in the drawable directory;

2) All icon files are placed in the Mipmap directory.

Why is that? Because the XML file and the. 9 file itself are with the zoom function, can adapt to different screens, and the icon image is generally adapted to different screens, may need to be placed under different sub-folders, if all placed in the drawable directory, will be very chaotic, and the icon image in the Mipmap directory, will appear very clear.

In addition, when the latest version of the layout layouts file invokes the resource, it is already possible to call the Mipmap directory file directly by default. When the app loads, it automatically calls the corresponding size bitmap, and if it doesn't, it looks down from the xxxhdpi directory.

In addition, it should be noted that the same picture if placed in a different directory, the final display on the phone is not the same effect, why?

Because for each bitmap under the Mipmap directory, the system accountant calculates the independent pixel size of the picture, such as a 36*36px picture, if placed in the MDPI subdirectory, because the directory corresponds to the DPI is 160, the scaling factor is 1.0, so the system calculates the independent pixel size is also 36* 36DP; If the image is placed in the hdpi directory, the corresponding DPI is 240, the scaling factor is 1.5, the system calculates the image of the independent pixel is 24*24DP. Converted to independent pixels of the picture, can be used to adapt to a variety of sizes.

So it seems that only a set of pictures can be prepared to meet the needs of different sizes. Which size is used, the common ones are ldpi, MDPI, hdpi, xhdpi, xxhdpi, xxxhdpi, and the scaling factor is 0.75,1,1.5,2,3 respectively. If using a smaller size, when used on the higher resolution of the phone, the image magnification is too high, certainly not clear, if the use of larger size, it will certainly take up too much resources, the installation package is large, after loading the memory will be larger. Considering the size of the scale factor 2.0, it is appropriate to choose the dimension. At this time, your app layout needs a large number of DP pictures, let the UI cut into twice px picture, put in the mipmap-xhdpi directory, you can be very good to meet the needs of various size screen!



Android Image Resource Processing

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.