Center a button in a Linear layout

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

    If you want to center an item in the middle of the screen don't use a LinearLayout as these are meant for displaying a number of items in a row.

    Use a RelativeLayout instead.

    So replace:

    android:layout_gravity="center_vertical|center_horizontal"
    

    for the relevant RelativeLayout option:

    android:layout_centerInParent="true"
    

    So your layout file will look like this:

    
    
    
        
    
    
    

提交回复
热议问题