Android,如何使两个按钮具有相同的宽度

Pac*_*chu 1 xml android

我试图将两个按钮彼此相邻放置在xml上,我希望它们的大小都相同(距离屏幕宽度的一半)-这是我的xml:

<LinearLayout
        android:layout_width="fill_parent"
        android:orientation="horizontal"
        android:id="@+id/linearLayout2"
        android:layout_height="fill_parent"
        android:gravity="bottom"
        android:weightSum="2">
    <Button
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/bAddDelete"
        />

    <Button
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/bMainMenu"
         />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

一切正常,但是当我在java中更改文本时,宽度也在变化,我如何使它们具有相同的大小?

谢谢

Mar*_* S. 5

设置视图的权重时,不应为宽度/高度使用任何值。将按钮的宽度设置为0dp。您也不需要android:weightSum =“ 2”

<LinearLayout
    android:layout_width="fill_parent"
    android:orientation="horizontal"
    android:id="@+id/linearLayout2"
    android:layout_height="fill_parent"
    android:gravity="bottom">
<Button
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:id="@+id/bAddDelete"
    />

<Button
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:id="@+id/bMainMenu"
     />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)