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