Android drawable folder usage

Source: Internet
Author: User

Android drawable folder usage

I have been learning to understand a simple game since I started school. After writing the code, it is found that some images on the main interface are much larger than normal.
I thought it was a code error. I checked the code back and forth. There was no error... Crashed !!!
Later, I tried to move the image from drawable-mdpi to the hdpi folder. It was good when I ran the program !! MyGod, the simpler the things, the more prone to errors. You can only blame yourself for not doing well. Android provides developers with two methods to solve the adaptation problem. The first method is to use the dip unit (dip: device independent pixels (device independent pixels ).
Different devices have different display effects, which are related to the hardware of the device. We recommend that you use this function to support WVGA, HVGA, and QVGA without pixels );
The other is to use different drawable folders, such: -The hdpi is similar to the screen with an advanced display density of DPI. The mdpi is similar to the screen with an intermediate display density of DPI. The ldpi is similar to the screen with a low-level display density of DPI. the scale ratio of the screen image indicated by density is 3: 4: 6: 8 ldpi, mdpi, hdip, and xhdipAndroid systems select image resources in different folders Based on the screen size and size of the mobile phone, in this way, the adaptation of screen resolutions of different sizes is realized. For example, on a low-resolution mobile phone, Android will select the image in the ldpi folder, but if the related resource file is not found in the ldip folder,
The Android system first selects a file from the hdpi folder and then scales the image resources to display them on the screen. If the hdpi Folder does not exist,
It will be searched in the default drawable folder. Therefore, if the picture is put in the wrong folder, the display size is different. Normally displayed image: enlarged image: The second image is displayed because the image under hdpi is placed in the default folder. The image itself is the same image. Because the system does not find the corresponding image in the hdpi folder, it is found in the default folder. However, the system will think that the image is suitable for medium-resolution screens,
If the image is directly placed on a high-resolution mobile phone, the system automatically scales up the image. Therefore, although the image is the same image, it is normal in reality. Similarly, if the same image is placed in the ldpi folder and displayed normally on a low-resolution mobile phone, but in the hdpi folder, the system considers the image to be displayed in a high-resolution manner,
To reduce the image size, the displayed image size is reduced.Therefore, an image is clearly displayed, but it is placed in different folders, and the display effect is different!

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.