Center a button in a Linear layout

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

    You can also set the width of the LinearLayout to wrap_content and use android:layout_centerInParent, android:layout_centerVertical="true":

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    >
    
    <ImageButton android:id="@+id/btnFindMe" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"       
        android:background="@drawable/findme"/>
    

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