Android CENTER_INSIDE 和 FIT_CENTER 比例类型之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11353973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between CENTER_INSIDE and FIT_CENTER scale types?
提问by Keith
I can't tell the difference between ImageView.ScaleType.CENTER_INSIDE
and ImageView.ScaleType.FIT_CENTER
.
我不能告诉之间的区别ImageView.ScaleType.CENTER_INSIDE
和ImageView.ScaleType.FIT_CENTER
。
CENTER_INSIDE
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
FIT_CENTER
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.
计算将保持原始 src 纵横比的比例,但也将确保 src 完全适合 dst。至少有一个轴(X 或 Y)将完全吻合。结果以 dst 为中心。
Can someone illuminate the difference between the two?
有人可以阐明两者之间的区别吗?
回答by Pang
Here's a graphical illustration of the difference between CENTER_INSIDE
and FIT_CENTER
.
这是CENTER_INSIDE
和之间差异的图形说明FIT_CENTER
。
Image used (100 × 100):
使用的图像(100 × 100):
Small image view (75 × 50):
小图像视图 (75 × 50):
CENTER_INSIDE:
中心_内部:
FIT_CENTER:
FIT_中心:
Both CENTER_INSIDE
and FIT_CENTER
shrink the image.
无论CENTER_INSIDE
和FIT_CENTER
缩小图像。
Large image view (300 × 200):
大图像视图(300 × 200):
CENTER_INSIDE:
中心_内部:
FIT_CENTER:
FIT_中心:
CENTER_INSIDE
does not enlarge the image, FIT_CENTER
does.
CENTER_INSIDE
不会放大图像,FIT_CENTER
会。
The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.
Android 机器人是从 Google 创建和共享的作品中复制或修改的,并根据知识共享 3.0 署名许可中描述的条款使用。
回答by BlackHatSamurai
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.
FIT_CENTER 将确保源完全适合容器,并且水平或垂直轴将是精确的。
CENTER_INSIDE is going to center the image inside the container, rather than making the edges match exactly.
CENTER_INSIDE 将使图像在容器内居中,而不是使边缘完全匹配。
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.
因此,如果您有一个 10" x 10" 的方形框和一个 8" x8" 的图像,则 CENTER_INSIDE 将直接位于框的中间,源容器和目标容器之间有 2"。
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.
使用 FIT_CENTER,上例中的相同图像将适合整个容器,因为边相等,并且一个轴将匹配目的地。使用 FIT_CENTER,如果您有一个 5" x 10" 的框和一个 5" x 7" 的图像,图像将按比例缩放,因此其中一个轴将适合,但仍将图像居中目的地。
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.
它们很相似,但制作一个是为了让源尽可能多地填充目的地,而另一个只是将图像放在目的地内。
Hope that clarifies a little
希望能澄清一点
回答by Zarokka
They are the same if the image is bigger than the container. If the image is smaller then the container CENTER_INSIDE will NOT scale the image up while FIT_CENTER will.
如果图像大于容器,它们是相同的。如果图像较小,则容器 CENTER_INSIDE 不会放大图像,而 FIT_CENTER 会。
回答by Code_Adda
the same if the image is bigger than the container. If the image is smaller then the container CENTER_INSIDE will NOT scale the image up while FIT_CENTER will.
如果图像大于容器,则相同。如果图像较小,则容器 CENTER_INSIDE 不会放大图像,而 FIT_CENTER 会。