Home > Mobile >  The difference between the gravity and layout_gravity in Android
The difference between the gravity and layout_gravity in Android

Time:10-05

Learning android today when the first line of code, using gravity="center" of the textview center content, according to the result error into the layout_gravity="center", run, find words position has not changed,
BBS checked, found both to,
Gravity is decided to control how content is inside control positioning,
Layout_gravity is decided to control how in his father's layout position,
The appended drawings

CodePudding user response:

Gravity, in themselves, the contents of the control center will based on current control matrix, according to
Layout_gravity the control relative to the parent layout position, of course the parent layout if set in the middle and you to the location of the layout is preferred,
 & lt; ? The XML version="1.0" encoding="utf-8"?> 
XMLNS: android="http://schemas.android.com/apk/res/android" android: layout_width="match_parent
"Android: layout_height="match_parent"
Android: gravity="center" & gt;
Android: layout_width="match_parent"
Android: layout_height="@ dimen/dp_12"
Android: text="DDDDD"
Android: gravity="center"
Android: layout_gravity="bottom"/& gt;



, not all the layout of the effective, RelativeLayout, FrameLayout, are based on the relative position, or the frame of the press, specific issues
  • Related