Objective:
1. Learn how to insert images in Android
Image addition allows you to add less color to your program. We use an androidrobot (picture.jpg) as an example. You can use any of your own images for testing.
It is generally recommended that you add images in your program to resources, instead of reading images in the SD card as a stream. After all, the embedded resources are safer and cannot be tampered.
1. Import images to resources
Drag the image to the three folders starting with res \ drawable. They represent high, medium, and low degrees of attention. Android automatically optimizes image reading. You can select an appropriate image for display. For example, you can store images of 128*128 at high resolution and 32*32 at low resolution.
2. Create an ImageView in the XML layout file:
Copy codeThe Code is as follows: <ImageView android: src = "@ drawable/picture"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
</ImageView>
3. Run the program and check the effect: