Android TableLayout 行权重

use*_*366 1 android android-layout android-xml

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

希望有人能帮助我了解这有什么问题

结果是这样的

我想要的是

在此输入图像描述

我的代码是:

<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>
Run Code Online (Sandbox Code Playgroud)

小智 5

请设置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" />
Run Code Online (Sandbox Code Playgroud)

希望能帮到你