2013-05-20 27 views
1

我有一個GridLayout,並且佈局中會有兩個或更多按鈕,並且所有按鈕都必須具有相同的寬度。 我的問題是,當按鈕具有不同的文本行號時,按鈕的marginTop也會不同。 我該如何解決這個問題? 謝謝。Gridlayout中的Android按鈕沒有相同的邊距頂部

<GridLayout 
    android:id="@+id/grid_buddies" 
    android:columnCount="4" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <Button 
     android:layout_width="60dp" 
     android:layout_height="match_parent" 
     android:text="TEST"/> 
    <Button 
     android:layout_width="60dp" 
     android:layout_height="wrap_content" 
     android:text="TESTDDFF"/> 
</GridLayout> 

這裏是圖片:

enter image description here

+0

您可以更改按鈕上的文字大小,使其能夠適應。 –

回答

0

使用android:layout_gravity="fill_vertical"在你的按鈕屬性與文本TEST

<GridLayout 
    android:id="@+id/grid_buddies" 
    android:columnCount="4" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <Button 
     android:layout_width="60dp" 
     android:layout_height="match_parent" 
     android:text="TEST" 
     android:layout_gravity="fill_vertical"/> 
    <Button 
     android:layout_width="60dp" 
     android:layout_height="wrap_content" 
     android:text="TESTDDFF"/> 
</GridLayout> 
+0

非常感謝!現在我會嘗試將其轉化爲programmaticaly。 – JamesChiang

+0

哦,不...我認爲LayoutParams.gravity = Gravity.FILL_VERTICAL不起作用。 – JamesChiang