How to align LinearLayout at the center of its parent?

前端 未结 14 2025
北荒
北荒 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条回答
  • 2020-12-04 10:17

    Try <TableRow android:gravity="center_horizontal"> This will center the inner LinearLayout within the tablerow.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题