What gravity:center attribute stands for


#1

I believe book forgot the explain this particular attribute in the first chapter and wondering what it do? Though “center” - the value is self-explanatory and “gravity” - the attribute is not.


#2

If you want some more detail on how some different attribute types work, you can find it in Chapter 8, if you’d like to skip ahead. (We will probably never be able to have extensive coverage of layout attributes in chapter 1, since there’s so much ground to cover.)

Anyway, to give you an answer: layout_gravity is an instruction to the parent layout widget. It says, “Pull this widget in the specified direction.” So if you say layout_gravity=“left”, it will pull the widget left, to sit on the left side of the FrameLayout. If you say layout_gravity=“right|top”, it will pin the widget to the top right corner.