What's the difference between CENTER_INSIDE and FIT_CENTER scale types?

一世执手 提交于 2019-11-30 10:07:55

问题


I can't tell the difference between ImageView.ScaleType.CENTER_INSIDE and ImageView.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

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?


回答1:


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 is going to center the image inside the container, rather than making the edges match exactly.

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.

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.

Hope that clarifies a little




回答2:


Here's a graphical illustration of the difference between CENTER_INSIDE and FIT_CENTER.


Image used (100 × 100):


Small image view (75 × 50):

CENTER_INSIDE:

FIT_CENTER:

Both CENTER_INSIDE and FIT_CENTER shrink the image.


Large image view (300 × 200):

CENTER_INSIDE:

FIT_CENTER:

CENTER_INSIDE does not enlarge the image, FIT_CENTER does.


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/11353973/whats-the-difference-between-center-inside-and-fit-center-scale-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!