1

我有一个 GridLayout,布局中会有两个或多个按钮,并且所有按钮必须具有相同的宽度。我的问题是,当按钮的文本行数不同时,按钮的 marginTop 也会不同。我怎样才能解决这个问题?谢谢。

<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>

这是图片:

在此处输入图像描述

4

1 回答 1

0

在您的 Button 中使用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>
于 2013-05-20T07:15:16.020 回答