One 、 introduction

ImageView Inherited from View Components , The main function is to display pictures , In fact, it's not just pictures that he can show ,Drawable Objects can be used ImageView To display .

ImageView Derived ImageButton、ZoomButton And so on , Specific derivation and inheritance relations can be viewed API file , It's really slow for me to open it , No more screenshots .

Local API It's too slow to open , I wanted to give up the screenshot , But I saw it on the Internet android api Chinese website , Good opening speed , So the inheritance relationship is as follows :

Here we can see ,ImageView Inherited from View, The direct subclass is ImageButton and QuickContactBadge, The indirect subclass is ZoomButton.

I'll also post this here API Online website , Open the slow one and try this one :

1:API chinese API

Two 、ImageView Supported by XML Properties and methods

XML attribute

Related methods


android:adjustViewBounds setAdjustViewBounds(boolean) Set up ImageView Whether to adjust the border to maintain the aspect ratio of the displayed image
android:cropToPadding setCropToPadding(boolean) If this property is set to true, The component will be intercepted to keep the ImageView Of padding
android:maxHeight setMaxHeight(int) Set up ImageView The maximum height of
android:maxWidth setMaxWidth(int) Set up ImageView The maximum width of
android:scaleType setScaleType(ImageView.ScaleType) Set how the displayed image zooms or moves to fit ImageView Size
android:src setImageResource(int) Set up ImageView What is shown Drawable Object's ID

scaleType It's an important attribute , It can be set to the following values :



ImageView.Scale.MATRIX Use Matrix Way to zoom
ImageView.Scale.FIT_XY Horizontal to the picture 、 Scale vertically independently , Make the graph completely suitable for ImageView, The aspect ratio of the image may change
ImageView.Scale.FIT_START Keep the aspect ratio scaled , Until it's fully visible in the picture ImageView, from ImageView It's starting to show up in the upper left corner of
ImageView.Scale.FIT_CENTER Keep the aspect ratio scaled , Until it's fully visible in the picture ImageView, from ImageView In the middle of
ImageView.Scale.FIT_END Keep the aspect ratio scaled , Until it's fully visible in the picture ImageView, from ImageView The lower right corner of the display
ImageView.Scale.CENTER Put the picture in ImageView middle , No scaling
ImageView.Scale.CENTER_CROP Keep the aspect ratio and zoom the image so that it can be completely covered ImageView, The shortest edge of the most important picture can be displayed .
ImageView.Scale.CENTER_INSIDE Keep the aspect ratio scaled , So that ImageView Can display the picture completely

In order to control ImageView,API The following operation methods are provided :

Method name


setImageBitmap(Bitmap bm) Use Bitmap Object settings ImageView Pictures shown
setImageDrawable(Drawable drawable) Use Drawable Object settings ImageView Pictures shown
setImageResource(int resId) Use resources ID Set up ImageView Pictures shown
setImageURI(Uri uri) Using pictures URI Address settings ImageView Pictures shown

3、 ... and 、ImageView Easy to use

ImageView Is relatively simple , Here is a simple image browser demonstration with the example of crazy three ImageView How to use .

The sample code is as follows :

The page layout is mainly linear , A linear layout is nested above , It's used to put three buttons in the middle , The main function is to switch pictures and increase or decrease transparency .

The background code is shown in the figure below :

Simple code , In circles 1 Part of the main completion button 1 That is “ Next ” The function of . In circles 2 Partially complete the increase or decrease of transparency , Screen display problem transparency reduction part of the code screenshot is incomplete , But you can make it up by yourself , Test it in private ImageView More features .

Four 、ImageView Other examples of online learning for

What we can learn from books is the basic usage , And for more ways to expand the use of the vast number of omnipotent omnipotent users have also shared a lot , No more here COPY And paste , I'll give you the address directly , For your own reference .

1. Illustration android in ImageView Of scaletype attribute

2.Android ApiDemos Series analysis 【View-ImageView/ImageButton】

3.Android in ImageView The stack application of

4.Android The road to learning and development 4—— Picture shows imageVIew

5. Simply drag the picture with your finger , Slide the picture back and forth to show the app -Gallery and BaseAdapter as well as ImageView Use

6.ImageView How to display pictures in full screen ImageView Draw the switch button

8.Android imageview Touch more

9. About ImageView Picture cycle the effect of a running Lantern

5、 ... and 、ImageButton and ZoomButton

Button And ImageButton The difference is that ,Button The button shows the text , and ImageButton The picture shown on . One thing to note is for ImageButton Set up Text Attributes don't work , Because essentially ImageButton yes ImageView, Even if you specify Text attribute , It doesn't show any text . If you use ImageButton Words , The picture button can specify src attribute , This property can Set static pictures , You can also set custom Drawable object , Realize the user-defined picture button .

and ZoomButton You can see from the literal that he is a magnifying / The button for the zoom out function , It is inherited from ImageButton, The usage is basically similar to ImageButton,android By default btn_minus、btn_plus Two Drawable resources , As long as give src Attribute to assign these two resource values , The corresponding button style can be realized .

Android There is also a ZoomControls Components , This component is equivalent to a combination of “ Zoom in ”,“ narrow ” Two buttons , And allow them to bind different listeners .(ZoomButton It's a single button ,ZoomControls It's a combination of two buttons ).

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

The explanation is as follows :

1. The first button is src yes btn_ok It's a blue button icon , I downloaded the button myself from the Internet , This is a fixed button icon .

2. The second button is the variable button , The button is green by default , Press and it turns red , It turns green when it's released , Used selector Resource file definition , The code will be posted below .

3. Use LinearLayout Linear layout , The content added a couple of ZoomButton, Use the system's own zoom in and zoom out icon to display ,Linearlayout The layout of is set to center horizontally .

4. Defined a ZoomControls Components , We can see that he himself has two buttons .

Which gives btn_Selector The code for is as follows :

The main settings are the pictures displayed when the button gets the focus and the pictures displayed when the button is pressed , The last line sets the default display picture .

6、 ... and 、QuickContactBadge

QuickContactBadge Inherited ImageView, The essence of it is also pictures , It can also be done through android:src Property to specify the picture it displays .QuickContackBadge The extra feature is : This image can be associated with a specific contact in the phone , When the user clicks on the image , The system will open the contact information interface of the corresponding contact person .

Because my virtual machine can't add contacts , So I'm not going to do code demonstration alone , Give me a few learning addresses , Learn from .

1.Android2.2 API Chinese document series (8) —— QuickContactBadge

2. Use QuickContactBadge Associated contacts

7、 ... and 、 Postscript

Because of work , Learning is also intermittent , But I think I will encourage myself to learn slowly , Sharing learning experience can also deepen memory . I hope that after reading the article, friends who feel useful to me can give me some encouragement , Thank you. .

Android Develop self study notes (Android Studio)—4.3ImageView And its subclasses

  1. Android Develop self study notes (Android Studio)—4.1 Layout components

    One . introduction Android The interface is completed by layout and components , A layout is like a frame in a building , The components are the bricks and tiles in the building . The components are arranged according to the requirements of the layout , It forms the interface that the user sees . stay Android4.0 Before , We usually say ...

  2. Android Develop self study notes (Android Studio)—4.5 ProgressBar And its subclasses

    One . Preface ProgressBar Itself represents the progress bar component , It also spawns two common components :SeekBar and RatingBar, They use it in a similar way , It's just that there's a certain difference in the display interface . Let's see API Description in document : From the picture ...

  3. Android Develop self study notes (Android Studio)—4.4 AdapterView And its subclasses

    One . introduction       AdapterView Itself is an abstract class , And its derived subclasses are basically similar in usage , It's just that there's a certain difference in the display , So put them in the same category .       AdapterView Has the following characteristics : Ada ...

  4. Android Develop self study notes (Android Studio1.3.1)—3.Android Applying structural analysis

    One .R What is the file ?      As shown in the figure above , We can go through findViewById Method by passing in Find our TextView Elements ,findViewById The method is also easy to understand , from View Pass through Id ...

  5. Android Develop self study notes (Android Studio1.3.1)—1. Environment building

    One . introduction .Google To launch the without doubt , This is its biggest advantage ,Android Stuido yes Google Introduction , Specially for Android" Make to measure " Of , yes Google A strong support is based on I ...

  6. Android Develop self study notes (Android Studio1.3.1)—2. Start the first one Android application

    One . Preface      Use Android Studio Development Android Application is a very simple thing , Because it will help you automate a lot of work . In this article, we mainly complete a simple application of clicking the button to display the current time in the text box , Here's a demonstration ...

  7. Android Develop self study notes (Android Studio) Catalog

    The development environment is as follows : operating system :Windows 10 Pro IDE:Android Studio 1.3.X Or later For others, please refer to the article description . 1. Environment building 1.1 ( Off the coast )AndroidStudio often ...

  8. Android Develop self study notes (Android Studio)—4. Interface programming and View Brief introduction of components

    One . introduction Android The most important part of application development is interface development , No matter how good your program contains , Without a good user interface , In the end, it will be abandoned by users .Android SDK Provides a large number of feature rich UI Group ...

  9. Android Develop self study notes (Android Studio)—4.2TextView And its subclasses

    One . introduction TextView It's the most common control we use , It is similar to C# Winform In program Lable,Java Swing Programming JLable, But it's more powerful , But in terms of function , It's actually a text editor ...

Random recommendation

  1. MySQL 5.7 Installation tutorial

    Preface : It's going to be used again recently Mysql, Record how to install it before you find Youdao's notes mysql5.7 The notes , I found that it was more casual to remember notes at that time , It's hard to see , Now I've decided to blog again , So that it will be more convenient for you to check it later . 1 ...

  2. Eclipse The plugin is recommended

    1.Eclipse Color plug in Code Analysis http ...

  3. About installing multiple... On the same machine sql Instance connection method

    Because the client needs to install two sql The server ( One sql2000, One is sql2005, In fact, the names of the examples are different ), Default port 1433 Installed first sql2000 Use , Later, the installation enabled one at random 3045 port . among ...

  4. C# Call in C++ Of dll The parameter of is the exported function of pointer type ( Including the case of secondary pointer )

    Strictly speaking, this article is not C++ Scope , But it's a little bit off the hook , Still in their own blog Let's record it in the book . C++ It's a common practice to use pointers in , It's also very easy to use , That's why I like C++ One of the reasons . But in C# The concept of trusteeship is emphasized in this article ...

  5. C puzzles Detailed explanation 【6-8 topic 】

    Sixth question #include<stdio.h> int main() { ; switch(a) { ': printf("ONE\n"); break; ': print ...

  6. JS monitor div Of resize event

    Original address : demand A common problem in the development process is how to monitor a div Of size change .  For example, I use c ...

  7. oracle word

    OEM Blackouts n. Ambush : Light control (blackout Complex number )Projection n. Project : planning : prominent : launch : speculation premium adj. High priced : Quality ############## ...

  8. php Underlying variable analysis

    <?php // An array reference $arr = array('a','b','c','d'); $x = & $arr[1]; $tmp = $arr; $arr[1] = 'e'; echo ...

  9. C The language is cold, knowledge points summary

    1.C What does the parameter type in the language function declaration mean when it is written after the right bracket ? As shown in the following code : int add(a, b) int a; int b; { return a + b; } What does a statement like this mean , I tested it in gcc ...

  10. Postman A concise tutorial

    One .Postman brief introduction Postman Is an interface testing tool , Commonly used in daily work interface class function test and simple automation test . Two .Postman Function is introduced 1. common get The requested interface test We now have a way to get information about students ...