Use of Android drawable and its related classes

A pleasing interface is very important for software, so graphics and image resources are also very important. This lecture will talk about the most important class drawable for processing graphics and images in Android. Drawable is the abstraction of an object that can be drawn (a little awkward, you can make do with it). The following is its inheritance relationship. You can see that bitmapdrawable, animationdrawable and other objects are its subclasses.

The simplest way to use drawable resources is to put the picture into the res \ drawable directory of the Android project, and the programming environment will automatically create a reference to this resource in the R class. You can use this reference to access the resource object. For example, R. drawable. Can be used for application icons in Java code Icon refers to it, which can be referred to in XML with @ drawable / icon.

So how to use picture resources when they are not in the project but in the sdcard? Let's take a look at the following examples to learn about the use of drawable and the use of bitmap and bitmapfactory.

1. Create project lesson23_ Drawable, the name of the main activity is maindrawable Java, copy a.jpg and b.jpg files to sdcard

2、res\main. The contents of XML are as follows:

3、MainDrawable. The contents of Java are as follows:

4、AndroidManifest. The contents of the XML are as follows (setting permissions)

5. Run the program to view the results:

Click the "view picture a" button, and ImageView loads picture a and displays it

Click the "set picture B as wallpaper" button to see that picture B has become a desktop wallpaper. All right, that's all for Ben.

The above is the data sorting of Android drawable, which will be supplemented in the future. Thank you for your support!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>