An article about android ImageView. ScaleType, imageview. scaletype
2016-01-10
At the beginning of android programming, there were a lot of questions about the ImageView. ScaleType network. I did not really understand it. This article aims to clarify this. If it is useful, please refer to the original address and author.
Typical code calls are as follows:
<ImageView android:layout_width="300dp" android:layout_height="400dp" android:scaleType="center" android:src="@drawable/numbers" > </ImageView>
For convenience, in all the examples below, the size of ImageView (I call it a container) is fixed at X DP, and only the image size is adjusted.
The image uses a 0-8 numeric lattice and adds a blue border of 10 PX. This makes it easy to see if the image has undergone deformation and cropping.
ScaleType has the following values:
1. The CENTER places the image in the middle of the container, but it does not adjust the image size. The size of the source image is as large as that of the container.
Image 100x100 image 300x300 image 400x400
2. CENTER_CROP scales up or down the image in proportion. The purpose is to adjust one side of the image to be equal to the container side, and the other side to be greater than or equal to the container side. it seems that the image must be stretched out.
Whether the image is 100x100, or 900x900, it is the result on the left side. One side (horizontal side here) is adjusted to the same size as the container, and the vertical side is adjusted to exceed the container.
3. Scale Up or down the image by CENTER_INSIDE to make the two sides of the image smaller than or equal to the container side. It seems that the image must be compressed.
Large Images
4. FIT_CENTER to zoom in or compress the image. The purpose is to adjust one side of the image to be equal to the side of the container, and the other side to be smaller than or equal to the side of the container. in addition, images must be placed in the container center.
No matter 100x100, or 900x900, the image will be strictly seed.
5. FIT_END is the same as FIT_CENTER, but the image is placed at the bottom right of the container.
6. FIT_START is the same as FIT_CENTER, but the image is placed in the upper-left corner of the container.
7. FIT_XY, regardless of the large image, simply and roughly pulls X and Y into the same size as the container.
To sum up,
1. the most common ones are FIT_CENTER, FIT_START, and FIT_END, because 1. it ensures the aspect ratio of the image and shows the coordination with the source image; 2. it makes at least one side close to the container, fully considering the container size.
2. FIT_XY is commonly used. The advantage is to ensure that the container is filled up. The disadvantage is that the image is distorted.
3. CENTER_CROP will cause the image to be cropped. CENTER_INSIDE is not applicable to small images and will make the image look small. The container is large and out of proportion. It can be replaced by FIT_CENTER.
4. The least commonly used is the CENTER, which does not adjust the image size at all. The container size is too restrictive and cannot be used on android multi-resolution devices.