How to Use ImageView of Android control series

Source: Internet
Author: User

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:

Related Article

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.