Android API Chinese Document ImageView

Source: Internet
Author: User

Android APIThe Chinese Document ImageView is the content to be introduced in this article, mainly to understand and learnAndroid APIContent, specificAndroid APIFor more information, see this article.

I. Android API Structure

 
 
  1. java.lang.Object  
  2. android.view.View  
  3. android.widget.ImageView 

Known direct subclass:

 
 
  1. ImageButton,QuickContactBadge 

Known indirect subclass:

ZoomButton

Ii. Android API Overview

Displays any image, sample mark. The ImageView class can load images from various sources, such as resources or image libraries). You need to calculate the image size, which can be used in other la S, and provide such scaling and coloring rendering) various display options.

3. XML attributes in Android APIs

Attribute Name Description

Android: whether adjustViewBounds maintains the aspect ratio. It must be used together with maxWidth and MaxHeight. Otherwise, it will not work if used separately.

Android: whether cropToPadding intercepts a specified area and replaces it with a blank area. The setting is ineffective and must be used with scrollY. The effect is as follows. For the implementation code, see the code section:

Android: maxHeight: sets the maximum height of a View. It is invalid when used separately and must be used with setAdjustViewBounds. If you want to set a fixed image size and keep the image aspect ratio, you need to set it as follows:

1) set setAdjustViewBounds to true;

2) Set maxWidth and MaxHeight;

3) set layout_width and layout_height to wrap_content.

Android: maxWidth sets the maximum width of a View. Same as above.

Android: scaleType sets the filling mode of the image.

Matrix0 plot with Matrix

FitXY1 stretch the image in proportion) to fill the width and height of the View

 
 
  1. layout_  
  2. height  
  3. :30px  
  4. layout_  
  5. width  
  6. :120px 

FitStart2 scales the image proportionally. The height of the image is the View height and displayed on the left side of the View.

FitCenter3 scales the image proportionally. After the image is stretched, the height of the View is displayed in the middle of the View.

FitEnd4 scales the image proportionally. After the image is stretched, the height of the View is displayed on the right of the View.

Center5 displays images based on the source image size. However, when the image width is higher than the View width, the middle part of the image is displayed.

 
 
  1. layout_  
  2. height  
  3. :60px  
  4. layout_  
  5. width  
  6. :80px  
  7. padding  
  8. :10px 

CenterCrop6 scales up the source image proportionally until the display is equal to the width and height of a View.

CenterInside7 when the source image width is high or equal to the width of the View, it is displayed in the center of the source image size; otherwise, it is scaled to the center of the width and height of the View.

Android: src: Set the drawable (slice or color, but you must specify the size of the View) of the View)

Android: tint renders the image into a specified color. See:

The source image is displayed on the left and the effect is displayed on the right. See the code below.

Iv. Android API code

1. android: tint

 
 
  1. <ImageView android:background="@android:color/white" android:src="@drawable/btn_mode_switch_bg" 
  2.         android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> 
  3.     <ImageView android:layout_marginLeft="5dp" android:background="@android:color/white" 
  4. android:tint="#ffff00" android:src="@drawable/btn_mode_switch_bg" 
  5.         android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> 

2. android: cropToPadding

 
 
  1. <ImageView android:background="@android:color/white" 
  2. android:scrollY="-10px" 
  3. android:cropToPadding="true" 
  4. android:src="@drawable/btn_mode_switch_bg" 
  5.        android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> 
  6.     <ImageView android:background="@android:color/white" android:scrollY="10px" 
  7. android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg" 
  8.         android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> 
  9.     <ImageView android:paddingTop="10px"  android:background="@android:color/white" 
  10. android:scrollY="10px" android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg" 
  11.         android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> 
  12.     <ImageView android:paddingTop="10px" android:background="@android:color/white" 
  13. android:scrollY="10px" android:cropToPadding="false" android:src="@drawable/btn_mode_switch_bg" 
  14.         android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> 

Summary:

Android APIThe ImageView content in the Chinese document is described.Android APIContent learning is helpful to you!

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.