CENTER_INSIDE 和 FIT_CENTER 比例类型有什么区别?

What#39;s the difference between CENTER_INSIDE and FIT_CENTER scale types?(CENTER_INSIDE 和 FIT_CENTER 比例类型有什么区别?)

本文介绍了CENTER_INSIDE 和 FIT_CENTER 比例类型有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法区分 ImageView.ScaleType.CENTER_INSIDEImageView.ScaleType.FIT_CENTER.

CENTER_INSIDE

均匀缩放图像(保持图像的纵横比),以使图像的两个尺寸(宽度和高度)都等于或小于视图的相应尺寸(减去填充).

Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).

FIT_CENTER

计算将保持原始 src 纵横比的比例,但也将确保 src 完全适合 dst.至少一个轴(X 或 Y)将完全适合.结果以 dst 为中心.

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. The result is centered inside dst.

有人能说明两者的区别吗?

Can someone illuminate the difference between the two?

推荐答案

FIT_CENTER 将确保源完全适合容器内部,并且水平轴或垂直轴都将是准确的.

FIT_CENTER is going to make sure that the source completely fits inside the container, and either the horizontal or vertical axis is going to be exact.

CENTER_INSIDE 将使图像在容器内居中,而不是使边缘完全匹配.

CENTER_INSIDE is going to center the image inside the container, rather than making the edges match exactly.

因此,如果您有一个 10" x 10" 的方形框和一个 8"x8" 的图像,则 CENTER_INSIDE 将直接位于框的中间,源容器和目标容器之间有 2".

so if you had a square box that was 10" x 10" and an image that was 8"x8", the CENTER_INSIDE would be directly in the middle of the box with 2" between the source and the destination container.

使用 FIT_CENTER,上例中的同一图像将适合整个容器,因为边相等,并且一个轴将匹配目标.使用 FIT_CENTER,如果您有一个 5" x 10" 的框和一个 5" x 7" 的图像,图像将按比例缩放,因此其中一个轴将适合,但仍会将图像居中在目的地.

With the FIT_CENTER, that same image from the example above, would fit the entire container, because the sides are equal, and one axis is going to match the destination. With FIT_CENTER, if you had a box that was 5" x 10", and an image that was 5" x 7", the image would be proportionally scaled, so one of the axis's would fit, but would still center the image inside the destination.

它们是相似的,但一个是为了让源尽可能地填充目标,而另一个只是将图像居中放置在目标内部.

They are similar, but one is made so that the source will fill the destination as much as possible, while the other just centers the image inside the destination.

希望澄清一点

这篇关于CENTER_INSIDE 和 FIT_CENTER 比例类型有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:CENTER_INSIDE 和 FIT_CENTER 比例类型有什么区别?

基础教程推荐