XML表格布局?两个等宽行充满了同样的宽度按钮? [英] XML Table layout? Two EQUAL-width rows filled with equally width buttons?

查看:1019
本文介绍了XML表格布局?两个等宽行充满了同样的宽度按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨继承人的一部分从我的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.

这篇关于XML表格布局?两个等宽行充满了同样的宽度按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆