2010-05-20 29 views
2

下面的线性布局。此布局在相对布局中对齐父级底部。问题是我希望所有按钮具有相同的高度。我曾尝试过layout_gravity =“fill”,但似乎并不奏效。等高的按钮

<LinearLayout android:id="@+id/button_layout" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:background="#FFFFFF" 
     android:layout_alignParentBottom="true"> 
    <Button android:text="Send" android:id="@+id/send_button" 
     android:layout_weight="1" android:layout_gravity="fill" 
     android:layout_width="0dip" android:layout_height="wrap_content"> 
    </Button> 
    <Button android:text="Report Missing Image" android:id="@+id/report_button" 
     android:layout_weight="1" 
     android:layout_width="0dip" android:layout_height="wrap_content"> 
    </Button> 
    <Button android:text="Close" android:id="@+id/close_button" 
     android:layout_weight="1" android:layout_gravity="fill" 
     android:layout_width="0dip" android:layout_height="wrap_content"> 
    </Button> 
</LinearLayout> 

回答

3

尝试将按钮上的layout_height设置为fill_parent。这将导致他们都占用父母的空间。用值3。而对于按键layout_weightsum参数的LinearLayout中,layout_weight为1

你并不需要指定的严重性:

+0

doh!有一个脑屁。任何想法为什么填充不这样做?你能结合底部填充等重力吗? – 2010-05-20 11:39:59

+1

我不确定...但layout_gravity =“fill”和layout_height =“wrap_content”似乎互相矛盾,所以android必须选择听取layout_height?我相信你可以结合这样的重力。 – 2010-05-20 16:45:02

1

,则应指定机器人。

4

对于相同的布局按键设置如下:

android:layout_weight="1" 
android:layout_height="fill_parent" 

这种方式,按钮都享有平等的权利,以填补父布局的高度,其高度将是相同的尺寸。