android:gravity和android:layout_gravity这两个属性相信大家平时用的都挺多的吧。有没有思考下两者的区别和不同呢?
我相信有些童鞋很清楚,有的童鞋却一知半解。今天我们就来看看两者的区别,希望以后能更好地帮助大家去使用这两个属性。
android:gravity 其实更多的是关注于控件本身,如果设置android:gravity="center",其本意是该控件内的内容是居中对齐的。
android:layout_gravity 其实更多的是关注于父控件或者嵌套在外层的布局,是相对于父控件而言的而不是自身内容的。如果设置android:layout_gravity="center_vertical|center_horizontal",
其本意是该控件相对于外层的布局是水平垂直居中的。
希望大家以后能够清楚准确的使用这两个属性。
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.