Android Development Self-study note (Android Studio) -4.3imageview and its subclasses

Source: Internet
Author: User

First, Introduction

ImageView inherits from the view component, the main function is to display the picture, in fact he can display not only the picture, the Drawable object can use ImageView to display.

ImageView derived ImageButton, Zoombutton, and other components, specific derivation and inheritance can see the API documentation, my side open is really slow, no longer.

Local API Open too slow, I would like to give up, but the internet to see the Android API Chinese site, open speed is good, so the inheritance relationship such as:

Here we can see that ImageView inherits from view, the direct subclass is ImageButton and Quickcontactbadge, and the indirect subclass is Zoombutton.

Here I also send this API online URL, open slow can try this:

1:API Chinese API

Ii. XML attributes and methods supported by ImageView

XML properties

Related methods

Description

Android:adjustviewbounds Setadjustviewbounds (Boolean) Sets whether ImageView adjusts its own boundaries to maintain the aspect ratio of the displayed picture
Android:croptopadding Setcroptopadding (Boolean) If this property is set to True, the component will be intercepted to retain the ImageView padding
Android:maxheight Setmaxheight (int) Set the maximum height of the ImageView
Android:maxwidth Setmaxwidth (int) Set the maximum width of the ImageView
Android:scaletype Setscaletype (Imageview.scaletype) Sets how the displayed picture is scaled or moved to fit the size of the ImageView
Android:src Setimageresource (int) Sets the ID of the Drawable object displayed by ImageView

ScaleType is an important property that can be set to the following values:

Value

Description

ImageView.Scale.MATRIX Zooming using the Matrix method
ImageView.Scale.FIT_XY Horizontal and vertical scaling of the picture, so that the graph is fully adapted to the ImageView, the picture aspect ratio may change
ImageView.Scale.FIT_START Hold the aspect ratio to scale the picture until it is fully visible to the ImageView, starting from the upper-left corner of the ImageView
ImageView.Scale.FIT_CENTER Maintain the aspect ratio to scale the picture until the diagram is fully visible to the ImageView, from the middle of the ImageView
ImageView.Scale.FIT_END Maintain the aspect ratio to scale the picture until the diagram is fully visible to the ImageView, from the lower-right corner of the ImageView
ImageView.Scale.CENTER Put the picture in the middle of the imageview without any zooming
ImageView.Scale.CENTER_CROP Maintain aspect ratio zoom picture so that the picture can completely cover the ImageView, most of the picture to the shortest side can be displayed.
ImageView.Scale.CENTER_INSIDE Keep the aspect ratio to scale the picture so that ImageView can fully display the picture

In order to control the IMAGEVIEW,API provides the following methods:

Method name

Description

Setimagebitmap (Bitmap BM) Use the Bitmap object to set the picture ImageView display
Setimagedrawable (drawable drawable) Use the Drawable object to set the picture ImageView display
Setimageresource (int resId) Use resource ID to set the picture displayed by ImageView
Setimageuri (URI Uri) Use the URI address of the picture to set the picture displayed by ImageView
Three, ImageView simple use method

ImageView's function is relatively simple, here to borrow a crazy three example to do a simple picture browser demonstration of the use of ImageView.

The sample code is as follows:

Page layout is mainly linear layout, the above nested a linear layout, for the center of the three buttons, mainly to achieve the ability to switch pictures and increase or decrease the transparency.

Background code such as:

The code is relatively simple, 1 parts of the circle is the main completion of Button 1 is the "next" function. 2 parts of the circle to complete the transparency of the increase or decrease, the screen display problem transparency of the reduction part of the code is not complete, but we can self-complement, privately test ImageView more features.

Iv. Other online learning examples from ImageView

In the book we can learn is the basic use of methods, and for more expansion of the use of the vast majority of omnipotent universal users have also shared a lot, here no longer do copy and paste, I directly give out the URL, we refer to it.

1. Graphical description of the ScaleType properties of ImageView in Android

2.Android Apidemos Series analysis "View-imageview/imagebutton"

ImageView Stack application in 3.Android

4.Android Learning and Development Road 4--picture Display ImageView

5. Simple finger drag picture, picture slide to show application-gallery and Baseadapter and ImageView use

How 6.ImageView pictures are displayed in full screen

7.android ImageView Draw Switch button

8.Android ImageView Multi-point touch

9. About the effect of ImageView picture Cycle Marquee

V. ImageButton and Zoombutton

The difference between a button and a ImageButton is that it displays text on the button, and a picture that appears on ImageButton. One thing to note is that setting the Text property for ImageButton is not useful, because essentially ImageButton is ImageView, and no text is displayed even if the Text property is specified. If you use ImageButton, the picture button can specify the SRC attribute, which can set a static picture, or you can set a custom drawable object to implement a user-defined picture button.

And Zoombutton literally can see that he is a zoom/Zoom button, which inherits from ImageButton, the use of the method is basically similar to imagebutton,android provided by default Btn_minus, Btn_ Plus two drawable resources, as long as the SRC attribute assigned to the two resource values, you can implement the corresponding button style.

Android also provides a zoomcontrols component that is equivalent to combining "zoom in", "Zoom Out" two buttons, and allow different listeners to be bound separately for them. (Zoombutton is a single button, Zoomcontrols is a combination of two buttons).

The following sample code demonstrates these components at the same time.

The description is as follows:

1. The first button SRC is Btn_ok is the blue button icon, I download the button myself from the Internet, this is a fixed button icon.

2. The second button is a variable button, the default display is green, the button is pressed to become red, released to green, using the selector resource file definition, the following will be posted code.

3. Using the LinearLayout linear layout, the content is added with a Zoombutton, using the system's own zoomed-out icon display, LinearLayout layout is set to horizontal center.

4. Define a Zoomcontrols component, and we can see that he has two buttons on his own.

The code that gives Btn_selector is as follows:

The main setting is the picture that is displayed when the button is focused and the picture that is displayed when you press it, and the last line sets the picture that appears by default.

Liu, Quickcontactbadge

Quickcontactbadge inherits the ImageView, its nature is also the picture, can also specify the picture which it displays through the ANDROID:SRC attribute. Quickcontackbadge Extras are: The picture can be associated to a specified contact in the phone, and when the user clicks the picture, the system opens the contact interface for the corresponding contact.

Because my side of the virtual machine is not added to the contact, so here is no longer a separate code demonstration, give a few learning addresses, refer to learning.

1.android2.2 API Chinese Document series (8)--quickcontactbadge

2. Associating contacts with Quickcontactbadge

Vii. PostScript

Because of the cause of work, learning is intermittent, but I think I will encourage myself to learn slowly, sharing learning experience can also deepen memory. Hope to read the article feel useful to their friends point a recommendation to me a little encouragement, thank you.

Android Development Self-study note (Android Studio) -4.3imageview and its subclasses

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.