Android imgview properties

ImageView is a control for displaying pictures on the interface.

①android:src="@drawable/img1";

SRC sets the picture, and the default picture is zoomed in and out to the most suitable size.

②android:background="@drawable/img1"

Background is a general property of components. You can not only set the background color of components, but also use pictures as the background.

[prompt] ① if the picture is used as the background, the picture will adapt to the size of the component.

② But if the width and height of the control is wrap_ Content, the effect is the same as that of SRC.

③ If the SRC and background properties are set at the same time, the picture set by SRC will be above and the picture set by background will be above. SRC pictures do not necessarily completely cover the following pictures, depending on the zoom mode of SRC.

④ The resource file name consists of lowercase letters, numbers and underscores. (Note: capital letters cannot be used)

③ Case

[preparation] the corresponding picture resources can be placed in the RES / drawable folder. This is because the two pictures are not zoomed

[Code]

[effect]

[prompt]

[prompt] ① to better illustrate the difference between background and SRC, we set the specific width of ImageView.

② Other attributes such as margin and constraintend are only used to adjust the position. It depends on your parent container.

③ The image on the left shows the background effect, and the image on the right shows the SRC effect. The image is not added as the background to observe the position and size of the ImageView.

android:scaleType="fitXY"

[tip] the scaletype attribute should be used together with the SRC attribute. It has no effect on the background set picture

[Code]

[attribute value]

Only the attribute values of scaletype are modified below

① Fixcenter: This is the default property value of the picture, which means that the control will be filled and the picture will not be deformed.

② Fixxy: represents a picture filling control. It allows the picture to stretch and will fit according to the size of ImageView. The same effect as background.

③ Centercrop: for the purpose of filling the whole ImageView, align the center of the ImageView with the center of the ImageView, and enlarge the original image in equal scale until it is filled with the ImageView (the width and height of the ImageView should be filled). The excess part of the original image should be cropped.

[effect]

④ Center: keep the size of the original image and display it in the center of ImageView. When the size of the original image is smaller than the size of ImageView, the next part will be blank, as shown in the left figure. On the contrary, the original image will be cropped, as shown in the figure on the right (here, change the size of ImageView to a value smaller than the original image)

[effect]

⑤ Matrix: without changing the size of the original image, draw the original image from the upper left corner of ImageView. The excess part of the original drawing will be cut.

[prompt] the effect of zooming in and out of ImageView with matrix is that the scaletype of ImageView must be set to matrix

⑥ Fitend: scale the original image to the width of ImageView and display it in the lower position. Left

⑦ Fitstart: scale the original image to the width of ImageView and display it at the top. Right picture

⑧ Centerinside: for the purpose of fully displaying the original image, the content of the picture is completely displayed in the center. The width and height of the original image reduced by scale is equal to or less than the width and height of ImageView. If the original image is smaller than the width and height of the ImageView, the original image will not be processed and will be displayed in the center on the ImageView (as shown in the left figure). On the contrary, it has the same effect as fixcenter. Take the short side as the benchmark, zoom the picture to the same scale, and display it completely in the middle of ImageView (as shown in the figure on the right).

android:adjustViewBounds="true/false"

Indicates whether the boundary can be adjusted to fit the picture (used with maxwidth or maxheight). This property is typically used with the maxheight and maxwidth properties. Maximum width and height.

[prompt] ① if the layout is set_ Width and layout_ If the height is a constant value, setting adjustviewbounds has no effect, and ImageView will be the width and height of the set constant value.

② If the layout is set_ Width and layout_ Height is wrap_ Content, it is meaningless to set adjustviewbounds, because ImageView will always have the same aspect ratio as the picture (but not the same aspect value, which will usually be enlarged)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>