1. 程式人生 > >Android技巧1—使用weights來居中views

Android技巧1—使用weights來居中views

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="horizontal"

    android:gravity="center"

    android:weightSum="1" >                   

    <Button

        android:layout_width="0dp"             ②

        android:layout_height="wrap_content"

        android:layout_weight="0.5"            ③

        android:text="Click me"

       />

</LinearLayout>