Center a button in a Linear layout

后端 未结 19 1320
遇见更好的自我
遇见更好的自我 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:37

    A commonly-used method that works with linear layout is to set a property on the image button

    android:layout_gravity="center"
    

    You can choose whether to left-align, center-align, or right-align each object in the linear layout. Note that the above line is precisely the same as

    android:layout_gravity="center_vertical|center_horizontal"
    

提交回复
热议问题