How to align LinearLayout at the center of its parent?

These two attributes are commonly confused:

  • android:gravity sets the gravity of the content of the View it’s
    used on.
  • android:layout_gravity sets the gravity of the View or
    Layout relative to its parent.

So either put android:gravity="center" on the parent or android:layout_gravity="center" on the LinearLayout itself.

I have caught myself a number of times mixing them up and wondering why things weren’t centering properly…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)