代码之家  ›  专栏  ›  技术社区  ›  Robby Pond

等高按钮

  •  2
  • Robby Pond  · 技术社区  · 14 年前

    下面是线性布局。此布局在相对布局中与父底部对齐。问题是我想要所有的按钮都有相同的高度。我试过布局_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 回复  |  直到 14 年前
        1
  •  3
  •   Cheryl Simon    14 年前

    尝试在按钮上设置布局高度以填充父级。这将导致它们全部占用父级中的空间量。

        2
  •  4
  •   Ömer    14 年前

    对于同一布局中的按钮,请设置以下内容:

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

    这样,按钮将具有相等的权限来填充父布局的高度,从而使其高度具有相同的大小。

        3
  •  1
  •   Karan    14 年前

    您应该为值为3的linearlayout指定android:layout的weightsum参数。对于按钮,布局权重为1。

    您不需要指定重力。