Android Interface Component----Image view

Source: Internet
Author: User

The ImageView component in the Android interface displays any object that is stored under drawable in the screen, usually the object type is a picture. When using ImageView to display pictures, it is common practice to copy the pictures to the Res/drawanle directory and access them through r.drawable.name.

a ImageView XML attribute

Android:adjustviewbounds confirm whether to adjust the aspect ratio of the displayed picture

android:maxheight Set the maximum height of the picture

android:maxWidth Set the maximum width of the picture

android:ScaleType Set How the image is scaled to fit the ImageView(the image size does not necessarily conform to the ImageView size)

android:src settings display the picture under Drawable, parameter is the picture name

android:tint for picture coloring, property is color value

two actual operation

Example: Image browser

We create a simple image browser, modeled after the photo browser of the Android phone

1> New Jian ' an project, add a linear layout to the layout, layout way we have XML form

2> prepare several pictures to copy to the project drawable directory. Note thatdrawable has several directories, such as drawable-hdpi, which correspond to different resolutions.

3> functions in the main activity: Get the linear layout, add the ImageView in turn

Final effect: (Looks ugly and has wood)

Code:

//Defining picture views and resource pathsPrivateimageview[] img =NewImageview[4];Private int[] Imgpath =New int[]{r.drawable.first, R.drawable.second, R.drawable.third, R.drawable.forth};//Initialize picture view, add layoutLinearLayout L =(LinearLayout) Findviewbyid (R.ID.S); img[0] =NewImageView ( This); img[0].setimageresource (imgpath[0]); img[0].setpadding (0, 0, 10, 10); L.addview (img[0]); img[1] =NewImageView ( This); img[1].setimageresource (imgpath[1]); img[1].setpadding (1, 0, 10, 10); L.addview (img[1]); img[2] =NewImageView ( This); img[2].setimageresource (imgpath[2]); img[2].setpadding (1, 0, 20, 10); L.addview (img[2]); img[3] =NewImageView ( This); img[3].setimageresource (imgpath[3]); img[3].setpadding (1, 0, 20, 10); L.addview (img[3]);

The level is limited, the insufficient place please leave a message! Thank you

Android Interface Component----Image view

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.