Android TableLayout,行上有权重

时间:2014-08-20 22:21:01

标签: android android-layout android-xml

我试图创建一个表并向表中的列添加相同的空格。我的代码在下面,但是我的第二个代码与第一个代码没有相同的空间。 就像你在我下面发布的图像上看到的那样,第一行(标题)与主体(第二行)没有相同的空间。

希望有人可以帮助我不要理解这个

的错误

Result is this

我想要什么

enter image description here

我的代码是:

<TableLayout
        android:layout_width="match_parent"
        android:layout_height="0dp">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="1" >

            <TextView
                android:layout_height="match_parent"
                android:layout_weight="0.6" />

            <ImageView
                android:layout_height="wrap_content"
                android:layout_weight="0.1"/>

            <ImageView
                android:layout_height="wrap_content"
                android:layout_weight="0.1" />

            <ImageView
                android:layout_height="wrap_content"
                android:layout_weight="0.1"" />

            <ImageView
                android:layout_height="match_parent"
                android:layout_weight="0.1" />
        </TableRow>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
              >

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                >

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="1" >

                    <TextView
                        android:layout_height="0dp"
                        android:layout_weight="0.6" />

                    <ImageView
                        android:layout_height="0dp"
                        android:layout_weight="0.1" />

                    <ImageView
                        android:layout_height="0dp"
                        android:layout_weight="0.1" />

                    <ImageView
                        android:layout_height="0dp"
                        android:layout_weight="0.1" />

                    <ImageView
                        android:layout_height="0dp"
                        android:layout_weight="0.1" />
                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="1" >

                    <RelativeLayout
                        android:layout_height="wrap_content"
                        android:layout_weight="0.6" >        

                        <TextView
                       android:layout_width="wrap_content"
                        android:layout_height="wrap_content" 
                       />

                    </RelativeLayout>

                    <TextView
                        android:layout_height="wrap_content"
                        android:layout_weight="0.1" />

                    <TextView
                        android:layout_height="wrap_content"
                        android:layout_weight="0.1" />

                    <TextView
                        android:layout_height="wrap_content"
                        android:layout_weight="0.1" />

                    <TextView
                        android:layout_height="wrap_content"
                        android:layout_weight="0.1" />
                </TableRow>
            </TableLayout>
        </ScrollView>
    </TableLayout>

1 个答案:

答案 0 :(得分:0)

请为layout_width="0dp"标签中的项目设置<TableRow>,请参见以下示例

<TableLayout
        android:layout_width="match_parent"
        android:layout_height="0dp">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="1" >

            <TextView
                android:layout_height="match_parent"
                android:layout_width="0dp"    <--Here-->
                android:layout_weight="0.6" />

希望能为您提供帮助