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
- java.lang.Object
- android.view.View
- android.widget.ImageView
Known direct subclass:
- 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
- layout_
- height
- :30px
- layout_
- width
- :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.
- layout_
- height
- :60px
- layout_
- width
- :80px
- padding
- :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
- <ImageView android:background="@android:color/white" android:src="@drawable/btn_mode_switch_bg"
- android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
- <ImageView android:layout_marginLeft="5dp" android:background="@android:color/white"
- android:tint="#ffff00" android:src="@drawable/btn_mode_switch_bg"
- android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
2. android: cropToPadding
- <ImageView android:background="@android:color/white"
- android:scrollY="-10px"
- android:cropToPadding="true"
- android:src="@drawable/btn_mode_switch_bg"
- android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
- <ImageView android:background="@android:color/white" android:scrollY="10px"
- android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg"
- android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
- <ImageView android:paddingTop="10px" android:background="@android:color/white"
- android:scrollY="10px" android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg"
- android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
- <ImageView android:paddingTop="10px" android:background="@android:color/white"
- android:scrollY="10px" android:cropToPadding="false" android:src="@drawable/btn_mode_switch_bg"
- 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!