从零开始学android-一行两个按钮居中 布局

方法一:

<RelativeLayout android:id="@+id/relativeTop" 
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        >
        
       <Button  
               android:id="@+id/btnGetMp3s"
            android:text="@string/strGetMp3List"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:gravity="center"
            android:layout_toLeftOf="@id/txtHide"
               />
       <TextView android:id="@+id/txtHide" android:layout_width="25" android:layout_height="1"
           android:layout_centerHorizontal="true" />
       <Button  
               android:id="@+id/btnExitSys"
            android:text="@string/strExitSys"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_toRightOf="@id/txtHide"
            
               />
    </RelativeLayout>

方法二:

<LinearLayout android:layout_width="fill_parent"

                android:layout_height="wrap_content"

                android:orientation="horizontal"

                style="@android:style/ButtonBar"

                >

                <Button android:id="@+id/btn_listview"

                    android:layout_height="wrap_content"

                    android:layout_width="0dp"

                    android:layout_weight="1"

                    android:text="ListView"/>

                <Button android:id="@+id/btn_emptyview"

                    android:layout_height="wrap_content"

                    android:layout_width="0dp"

                    android:layout_weight="1"

                    android:text="EmptyView"/>      

            </LinearLayout>
原文地址:https://www.cnblogs.com/dekevin/p/4286160.html