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