2017-03-15 66 views
0

我目前正在嘗試在線性佈局中獲得一個啓動屏幕,使其具有3個按鈕,每個按鈕在它們之間具有相等的空間,並且全部居中在屏幕上。到目前爲止,我的設置是非常基本的這種格式:沒有填充的居中按鈕

android:id="@+id/helpButton" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:text="@string/help" /> 

但是,只要我增加體重的按鈕垂直部分拉伸以填充多餘的空間,而不是僅僅爲中心的按鈕,我希望它。即使我手動使用dp,垂直部分仍然伸展。有人可以解釋這個問題的原因以及如何解決這個問題嗎?

+0

你想怎麼安排你的按鈕?垂直還是水平? –

+0

@HamidGoodarzi我希望他們垂直。我的線性佈局也有垂直方向。 –

回答

2

我創造了整個XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="Button" /> 

    </FrameLayout> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="Button" /> 

    </FrameLayout> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="Button" /> 

    </FrameLayout> 
</LinearLayout> 

enter image description here

0

給這個配置的鏡頭:

android:id="@+id/helpButton" 
android:layout_width="wrap_content" 
android:layout_weight="1.0" 
android:layout_height="0dip" 
android:layout_gravity="center_vertical" 
android:text="@string/help"