How to align LinearLayout at the center of its parent?

前端 未结 14 2030
北荒
北荒 2020-12-04 09:29

I\'ve looked through numerous similar questions here at SO, but nothing helps. I have a hierarchy of different nested layouts, all have android:layout_width=\"fill_par

14条回答
  •  Happy的楠姐
    2020-12-04 10:17

    I experienced this while working with nested RelativeLayouts. My solution ended up being simple, but it's a little gotcha that's worth being aware of.

    My layout was defined with...

    android:layout_height="fill_parent"
    android:layout_below="@id/someLayout
    android:gravity="center"
    

    ...however, I didn't think that the layout below this one was placed on top of it. Everything inside this layout was shifted towards the bottom instead of centered. Adding...

    android:layout_above="@id/bottomLayout"
    

    ...fixed my issue.

提交回复
热议问题