drawable Picture Resources

Source: Internet
Author: User

Manipulating pictures in Android is done through the Drawable class, Drawable class has many subclasses, such as Bitmapdrawable class for manipulating bitmaps ,colordrawable classes for manipulating colors , The shapedrawable class is used to manipulate shapes , and theanimationdrawable class is used to manipulate frame-wise animations .

drawable-hdpi ,drawable-ldpi ,drawable-mdpi , or drawable-xhdpi on Android apps When you add a picture resource file (for example, draw1.jpg) to any folder, an index entry is automatically created in the R.java file: R.DRAWABLE.DRAW1, these drawable folders are used to hold pictures of different resolutions. These folders can hold files of the same name, but only one resource index item will be generated in R.java , then which one will the system use when referencing? Depending on the resolution of the device on which the program is running, the image that is closest to the device resolution is selected automatically, and if the image file is included in only one folder, then the system has no choice but to use the file, even if its resolution is far from the device's resolution. This means that these folders exist primarily for use in different devices with different resolutions but the same content of the picture, so that the application has better flexibility and adaptability. The dimension relationships between the pictures in these several drawable folders are as follows:

After the resource index is generated, the Drawable object can be referenced either in the XML resource file through "@drawable/draw1" , or in Java code R.DRAWABLE.DRAW1 To access the picture.

Note: The image resource file name is not allowed in uppercase letters in Android, and the file name cannot begin with a number.

It should be noted thatr.drawable.draw1 is just a constant of type int , representing the resource ID of the Drawable object, if the actual drawable object needs to be obtained in a Java program, You can call the activity getresources () method inherited from Android.content.ContextWrapper to get all the resources, and then call the The getdrawable (intID) method to get the.

Getresources (). getdrawable (IntID);

drawable Picture Resources

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.