Android gravity values appended by "|" : What is the difference between, say "top|left" and "left|top"?

206 Views Asked by At

The android doc here and here says:
"Must be one or more (separated by '|') of the following constant values."

How does android process multiple gravity values like "top|center_horizontal"? Is it that it first places the object at the top and then position is at central horizontally?

What is the difference between, say "top|left" and "left|top"? Or is it that we always have to specify the vertical gravity first and then the horizontal gravity?

1

There are 1 best solutions below

0
On

Nothing. Android saves flags as an int, and uses bitwise OR to add flags. So for example, say LEFT was defined as 1, and TOP as 2. Then to store both, you could save 3. In binary this makes sense, you want 01 and 10, so you store 11. The operation that does this trick is bitwise OR, or '|'. This operation is reflexive, so LEFT|TOP == TOP|LEFT.