Center a button in a Linear layout

后端 未结 19 1322
遇见更好的自我
遇见更好的自我 2020-12-04 04:55

I am using a linear layout to display a pretty light initial screen. It has 1 button that is supposed to centre in the screen both horizontally and vertically. However no

19条回答
  •  無奈伤痛
    2020-12-04 05:28

    It would be easier to use relative layouts, but for linear layouts I usually center by making sure the width matches parent :

        android:layout_width="match_parent"
    

    and then just give margins to right and left accordingly.

        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
    

提交回复
热议问题