2013-05-31 24 views
0
<Button 
     android:id="@+id/btnSetDate" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_weight="1.0" 
     android:text="Set Date" /> 

<Button 
    android:id="@+id/btnSetTime" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_weight="1.0" 
    android:text="Set Time" /> 

如何居中兩個按鈕像圖像?Android:如何在中心放置兩個全寬按鈕?

enter image description here

回答

3

它很簡單!在這裏,我們去...

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/btnSetDate" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:text="Set Date" /> 

     <Button 
      android:id="@+id/btnSetTime" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:text="Set Time" /> 

    </LinearLayout> 

</RelativeLayout> 
2

只是包裝你的按鈕爲內容,如LinearLyaout,採用Android:重力=「center_vertical」,它會工作。

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="center_vertical" 
android:orientation="vertical" > 

<Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="btn1" > 
</Button> 

<Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="btn2" > 
</Button> 

</LinearLayout> 
相關問題