區別:
android:gravity:
是對該view中內容的限定.比如一個button 上面的text. 你可以設置該text 相對於view的靠左,靠右等位置.
android:layout_gravity :
是用來設置該view相對與父view 的位置.比如一個button 在linearlayout裏,你想把該button放在linearlayout裏靠左、靠右等位置就可以通過該屬性設置.
即android:gravity用於設置View中內容相對於View組件的對齊方式,而android:layout_gravity用於設置View組件相對於父類容器的對齊方式。
原理跟android:paddingLeft、android:layout_marginLeft有點類似。如果在按鈕上同時設置這兩個屬性。
android:paddingLeft="30px" 按鈕上設置的內容離按鈕左邊邊界30個像素
android:layout_marginLeft="30px" 整個按鈕離左邊設置的內容30個像素