XML表格布局?两个等宽行充满了同样的宽度按钮?宽度、表格、布局、按钮

2023-09-12 06:26:53 作者:Je suis très heureux 我很

嗨继承人的一部分从我的XML土地格式为:

Hi heres a part from my XML for LAND format:

<TableLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="center"
    android:stretchColumns="*">
<TableRow>    
    <Button
        android:id="@+id/countbutton"
        android:text="@string/plus1"/>      
    <Button
        android:id="@+id/resetbutton"
        android:text="@string/reset" 
        />  
</TableRow>
</TableLayout>

现在我不明白 - 一排的宽度,也该按钮则取决于按钮中的文本。如果两种文本equaly长可以说:TEXT其确定 - 该表的一半是在屏幕的中间。但是,如果他们有不同的大小 - 可以说A和这是长按钮可以在屏幕中间的表心不是中心了,所以按钮是不是同样的宽度......

And now what I dont get - the WIDTH of one row and also of the button depends on the TEXT inside the button. If the both texts are equaly long lets say : TEXT its ok - the table half is in the middle of the screen. But if they have different size - lets say "A" and "THIS IS THE LONG BUTTON" the CENTER of the table isnt in the middle of the screen anymore and so the buttons are not equally width...

推荐答案

要具有按钮在按钮,你需要做的同样大小的行。

To have buttons in rows where buttons are the same size you need to do.

    <LinearLayout android:orientation="horizontal" 
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">
         <Button android:layout_weight="1" 
             android:layout_height="wrap_content" 
             android:layout_width="0dip"/>
         <Button android:layout_weight="1" 
             android:layout_height="wrap_content" 
             android:layout_width="0dip"/>
    </LinearLayout>

和填写其他XML属性的按钮。

And fill in the other xml properties for your buttons.

神奇的是,在layout_weight和width属性。你并不需要的表格布局。这些属性告诉你的意见应占用的空间等于在父布局的布局。

The magic is in the layout_weight and width properties. You don't need the Table layout. These properties tell the layout that your views should take up equal space in the parent layout.