Is there any difference between “center_horizontal|center_vertical” and “center”

霸气de小男生 提交于 2020-02-03 05:31:05

问题


I want to center an image in a linearLayout.

Is there any difference between

android:gravity="center_horizontal|center_vertical"

and

android:gravity="center"

?


回答1:


No, there is no difference. According to source code

public static final int CENTER = CENTER_VERTICAL|CENTER_HORIZONTAL;



回答2:


There really is not difference between the two except that it's less code using center. combining center_horizontal and center_veritcal is the equivalent of center




回答3:


I know this is old question but i want just want to share to anyone what i found. And pardon the bad english.

Imagine Horizontal line as X an vertical line as Y (like the one used in 3d modeling model ex: maya and 3dmax).


(source: helpingwithmath.com)

center_horizontal = this one will put your view/layout postion of X into zero

center_vertical = as you guess, it will make the postion Y into zero

center = this one will make the position X and Y into Zero

I figured this out by my own when trying all of them on my layout. Cant give an example because my printscreen isnt working.

I dont know if there is a documentation that tell you about this, so correct me if im wrong. I just hope it will help someone understand :cheers.



来源:https://stackoverflow.com/questions/17892786/is-there-any-difference-between-center-horizontalcenter-vertical-and-center

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