2列TableLayout与每列50%完全相同 [英] 2-column TableLayout with 50% exactly for each column

查看:201
本文介绍了2列TableLayout与每列50%完全相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一次让我为难,因为我与Android的第一个步骤。我不能在2列使两列TableLayout每一个确切的50%。

This one puzzles me since my first steps with Android. I can't make both columns in a 2-column TableLayout exact 50% each.

下面是一个例子:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >

    <TableLayout
        android:id="@+id/tablelayout"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:paddingRight="2dip" >

        <TableRow>
            <TextView
                style="@style/TextViewStandard"
                android_layout_span="2"
                android:layout_weight="1" 
                android:text="Bla" />
        </TableRow>

        <TableRow>
            <TextView
                style="@style/TextViewStandard"
                android:layout_weight="1"
                android:text="Name:" />

            <EditText
                style="@style/EditTextStandard"
                android:id="@+id/et_name"
                android:layout_weight="1" />
        </TableRow>

        <TableRow>
            <TextView
                style="@style/TextViewStandard"
                android:layout_weight="1"
                android:text="URL:" />

            <EditText
                style="@style/EditTextStandard"
                android:id="@+id/et_url"
                android:layout_weight="1" />
        </TableRow>

        <TableRow>
            <Button
                style="@style/ButtonStandard"
                android:layout_column="0"
                android:layout_marginTop="6dip"
                android:onClick="onClickOk"
                android:text="@android:string/ok" />
        </TableRow>
    </TableLayout>
</ScrollView>

下面是相应的样式定义:

And here's the corresponding style definition:

<resources>
    <style name="ButtonStandard" parent="@android:style/Widget.Button">
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_width">fill_parent</item>
    </style>

    <style name="EditTextStandard" parent="@android:style/Widget.EditText">
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginLeft">2dip</item>
        <item name="android:layout_marginRight">2dip</item>
        <item name="android:layout_marginTop">2dip</item>
        <item name="android:layout_width">fill_parent</item>
    </style>

    <style name="TextViewStandard" parent="@android:style/Widget.TextView">
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginLeft">2dip</item>
        <item name="android:layout_marginRight">2dip</item>
        <item name="android:layout_marginTop">2dip</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:textColor">@android:color/white</item>
    </style>
</resources>

这变成真的搞砸了与相关的复选框。

This becomes really messed up with a CheckBox involved.

有什么毛病我的定义?

在预先感谢。 HJW

Many thanks in advance. HJW

推荐答案

您是否尝试设置的android:layout_width 属性 0dp (当然保持的android:layout_weight 1 )?对孩子的看法

Have you tried to set the android:layout_width attribute to 0dp (and of course keep the android:layout_weight as 1) on the child views?

我一直在相似的场景时,我也想给定的空间平均分配两个子视图之间却没有这样做,因为孩子更广泛的内容也成为更广泛,其母公司内,比它的兄弟姐妹。这是由于这样的事实,更广泛的孩子有一个更大的初始宽度。确保两个孩子从相同的宽度(机器人:layout_width =0dp他们两个)开始的,也保证均匀地分布它们之间的空间

I have been in similar scenarios when I also wanted to distribute the given space equally between two child views but failed to do so since the child with "wider content" also became wider, within its parent, than its sibling. This was due to the fact that the wider child had a greater initial width. Making sure both children started of from the same width (android:layout_width="0dp" on both of them) also guaranteed to distribute the space evenly among them.

这篇关于2列TableLayout与每列50%完全相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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