Android 为什么可以';在表格布局中混合文本行和图像行吗?

Android 为什么可以';在表格布局中混合文本行和图像行吗?,android,textview,row,tablelayout,Android,Textview,Row,Tablelayout,我的mainactivity Android.xml表格布局是一个简单的图像表格,3列4行。所有内容都设置为匹配父级宽度、高度和重量1,在GUI编辑器中呈现稍有错误,但在我的手机上呈现正常 然后,如果我在.xml底部行之前添加一行来添加文本标签,它要么根本不呈现该行,要么在稍微戳一下之后呈现文本,但将最后一行的底部切掉 下面是.xml,冗长但非常简单且重复 <TableLayout android:layout_gravity="bottom" android:layout

我的mainactivity Android.xml表格布局是一个简单的图像表格,3列4行。所有内容都设置为匹配父级宽度、高度和重量1,在GUI编辑器中呈现稍有错误,但在我的手机上呈现正常

然后,如果我在.xml底部行之前添加一行来添加文本标签,它要么根本不呈现该行,要么在稍微戳一下之后呈现文本,但将最后一行的底部切掉

下面是.xml,冗长但非常简单且重复

<TableLayout
    android:layout_gravity="bottom"
    android:layout_weight="1"
    android:stretchColumns="*"       
    android1:layout_width="match_parent"
    android1:layout_height="match_parent"
    android1:layout_alignParentBottom="true"
    android1:layout_alignParentLeft="true"
    android1:layout_alignParentRight="true"
    android1:layout_alignParentTop="true" >

    <TableRow
        android1:id="@+id/tableRow1"
        android1:layout_width="match_parent"
        android1:layout_height="match_parent"
        android1:layout_weight="1" >

        <ImageView
            android1:id="@+id/x2"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:clickable="true"
            android1:onClick="SetTable"
            android1:padding="5dp"
            android1:scaleType="fitCenter"
            android1:src="@drawable/menu_2x"
            android1:tag="2" />

        <ImageView
            android1:id="@+id/x3"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="SetTable"
            android1:padding="5dp"
            android1:scaleType="fitCenter"
            android1:src="@drawable/menu_3x"
            android1:tag="3" />

        <ImageView
            android1:id="@+id/x4"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="SetTable"
            android1:padding="5dp"
            android1:scaleType="fitCenter"
            android1:src="@drawable/menu_4x"
            android1:tag="4" />

    </TableRow>

    <TableRow
        android1:id="@+id/tableRow3"
        android1:layout_width="match_parent"
        android1:layout_height="match_parent"
        android1:layout_weight="1" >

        <ImageView
            android1:id="@+id/x5"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="SetTable"
            android1:padding="5dp"
            android1:scaleType="fitCenter"
            android1:src="@drawable/menu_5x"
            android1:tag="5" />

        <ImageView
            android1:id="@+id/x6"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="SetTable"
            android1:padding="5dp"
            android1:scaleType="fitCenter"
            android1:src="@drawable/menu_6x"
            android1:tag="6" />

        <ImageView
            android1:id="@+id/x7"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="SetTable"
            android1:padding="5dp"
            android1:scaleType="fitCenter"
            android1:src="@drawable/menu_7x"
            android1:tag="7" />

    </TableRow>

    <TableRow
        android1:id="@+id/tableRow4"
        android1:layout_width="match_parent"
        android1:layout_height="match_parent"
        android1:layout_weight="1" >

        <ImageView
            android1:id="@+id/x8"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="SetTable"
            android1:padding="5dp"
            android1:scaleType="fitCenter"
            android1:src="@drawable/menu_8x"
            android1:tag="8" />

        <ImageView
            android1:id="@+id/x9"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="SetTable"
            android1:padding="5dp"
            android1:scaleType="fitCenter"
            android1:src="@drawable/menu_9x"
            android1:tag="9" />

        <ImageView
            android1:id="@+id/x10"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="SetTable"
            android1:padding="5dp"
            android1:scaleType="fitCenter"
            android1:src="@drawable/menu_10x"
            android1:tag="10" />

    </TableRow>

    <TableRow
        android1:id="@+id/TableRow01"
        android1:layout_width="match_parent"
        android1:layout_height="match_parent"
        android1:layout_weight="1" >

        <TextView
            android1:id="@+id/TextView02"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_span="2"
            android1:layout_weight="1"
            android1:text="Left two buttons"
            android1:textColor="#000000"
            android1:textSize="16dp"
            android1:textStyle="normal" />

        <TextView
            android1:id="@+id/textView1"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:text="Right button"
            android1:textColor="#000000"
            android1:textSize="16dp"
            android1:textStyle="normal" />

    </TableRow>

    <TableRow
        android1:id="@+id/TableRow5"
        android1:layout_width="match_parent"
        android1:layout_height="match_parent"
        android1:layout_weight="1" >

        <ImageView
            android1:id="@+id/ImageView07"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="LaunchPR"
            android1:scaleType="fitCenter"
            android1:src="@drawable/pushbutton_1"
            android1:tag="1" />

        <ImageView
            android1:id="@+id/ImageView08"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="LaunchPR"
            android1:scaleType="fitCenter"
            android1:src="@drawable/pushbutton_1"
            android1:tag="2" />

        <ImageView
            android1:id="@+id/ImageView09"
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:layout_weight="1"
            android1:onClick="LaunchPR"
            android1:scaleType="fitCenter"
            android1:src="@drawable/pushbutton_2"
            android1:tag="3" />

    </TableRow>

</TableLayout>



如果设置
表格布局来填充父项(
匹配\u父项
),则不需要
布局权重
属性。如果您计划使
表格行
在垂直方向上占据相等的空间(例如,如果您有4行,则需要在
表格行
上设置
android:weightSum=“4”
android:layout\u weight=“1”上设置
android:weightSum=“4”
表格行上创建四个大小相等的垂直行(填充屏幕))


另外,
android:stretchColumns=“*”
属性将拉伸表中的所有列,这样您就不需要在
TableRow

的子级上设置布局权重。您还可以发布用于添加额外行的代码吗?对不起,我的措辞很糟糕。都在.xml中;我不会动态添加它。我的意思是,我让表格处理图像,然后用编辑器/xml添加新行您知道用于某些视图的属性是什么吗?我特别提到的是
layou-weight
,您似乎在所有视图中都使用了它。根据文档,权重应该是一个相对的比例因子。总重量为3,每个元素的重量为1,每个元素的比例为宽度的1/3。高度也一样。只有权重似乎不能正确处理带有文本字段的行。@Luksprog-没错,表设置为“按视图缩放”时,行权重是不必要的。加上这个作为答案,我会为你勾选它作为分数。;)在大屏幕上尝试我的界面,这似乎不是真的。我需要主表布局中的权重和为2,每行的权重和为1,否则它只能绘制到屏幕高度的一半。@TickledPink如果有4行,则
权重和应为4(并且权重在两行之间平均分配)。我不明白为什么这会在大屏幕上失败。我有嵌套的表。主包含表有两行,将屏幕分为上半部分和下半部分,在我添加权重之前,它只将屏幕的上半部分安装在一个大显示屏上。