It is believed that for Android beginners, everyone has been confused by the two extremely similar attributes in layout.
Simply use the search tool and we won't find the answer to the following:
Layout_gravity represents the position of the component itself in the parent component gravity represents the position of the subassembly in the component
It seems simple.
Why this simple truth, there are always classmates will find, at "some time", layout_gravity this attribute is not good, lost its due role
Where exactly is the problem?
When the LinearLayout property of the parent layout is android:orientation= "vertical", android:layout_gravity= "? " This will only take effect when the landscape is set to horizontal. such as: Left,right,center_horizontal and so on;
When the LinearLayout property of the parent layout is android:orientation= "Horizental", android:layout_gravity= "? " This is set to portrait when it takes effect. such as: Top,bottom,center_vertical and so on;
One of the more special is the center, whether it is horizontal or vertical, it always has a direction to work , because linearlayout he can only have a direction,
This nm, does make a person egg ache. In fact, there is a bit of truth, that is, linearlayout horizontal, if there are many children, then do not know who put the most right,
There are two ways to fix it,
(1) Use Relativelayout Bar, this is crap bar, haha
(2) in LinearLayout set android:gravity this from the official API explanation is how to place its content, linearlayout content is not his children, problem solving
Problems with Android layout_gravity failure