android:如何强制表行具有相同的高度?

android:如何强制表行具有相同的高度?,android,layout,height,tablelayout,tablerow,Android,Layout,Height,Tablelayout,Tablerow,我已经彻底搜索了google和stackoverflow,但我得到的唯一答案是:使用layout weight=“1”设置每个Tablerow。这不管用 现在我在表格布局中有八行,每行包含5个线性布局。每个线性布局包含2个TextView,而FontSizes的范围从TextView到TextView不等 事实证明,TableRows的高度不同,这取决于所包含的textView的字体大小。 奇怪的是,无论我将TableRows的布局高度设置为“0dp”还是“match\u parent”或“fi

我已经彻底搜索了google和stackoverflow,但我得到的唯一答案是:使用
layout weight=“1”
设置每个
Tablerow
。这不管用

现在我在
表格布局中有八行,每行包含5个
线性布局
。每个线性布局包含2个
TextView
,而
FontSizes
的范围从
TextView
TextView
不等

事实证明,TableRows的高度不同,这取决于所包含的
textView
的字体大小。 奇怪的是,无论我将TableRows的布局高度设置为“0dp”还是“match\u parent”或“fill\u parent”,都不会对布局产生任何影响

如何强制
表格行
具有相同的高度?我不想使用特定的pts值作为高度,因为tableRows必须在它们之间平均划分整个屏幕

这是xml的一部分,实际文件很大:

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="6"
    android:weightSum="8"
    tools:context=".MainActivity" >

    <TableRow
        android:layout_width="match_parent"
        android:layout_weight="1"
        tools:context=".MainActivity">

        <LinearLayout
            android:clickable="true"
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/btnmargintop"
            android:layout_marginBottom="@dimen/btnmarginbot"
            android:layout_marginLeft="@dimen/btnmarginleft"
            android:layout_marginRight="@dimen/btnmarginright"
            android:layout_weight="1"
            android:background="@drawable/bg" >

            <myapp.TypefacedTextView
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="@integer/layoutweight1"
                android:layout_gravity="center"
                stevens:typeface="myfont.otf"
                android:clickable="false"
                android:textSize="@dimen/fontsize1" />
            <myapp.TypefacedTextView
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="@integer/layoutweight2"
                android:layout_gravity="center"
                stevens:typeface="myfont.otf"
                android:clickable="false"
                android:textSize="@dimen/fontsize2" />              
        </LinearLayout>

您可能正在让选项卡的布局自动调整到内部内容的大小。解决问题有两种方法:

  • 确保所有元素共享相同的大小——也就是说,不要担心整个表,只要确保内部元素的尺寸相同即可
  • 或者简单地设置父布局的高度,不要让元素产生差异。这个解决方案的问题是,如果你的内部变得更大,你将没有空间,所以你可能想坚持第一种选择

请发布您的代码和XML。Phil,您能做点什么吗?我不太确定,但我认为选项1的意思是我将每行的高度设置为固定的pts值?不过我不想这样,因为那样的话,根据屏幕大小,表格不会填满屏幕……是的,完全正确!使所有元素的大小相同(=找到它可以拥有的最大大小),这样,所有行的高度都相同。为什么您需要在屏幕上安装它,它将调整+用户可以向下滚动;)谢谢你的帮助,但我需要它来适应屏幕。滚动不是一个选项。在这种情况下,选项二是正确的,您需要选择。将每行的
重量设置为相同,并使高度
填充\u父项
。这样,所有行的大小都相同,并且适合屏幕,无需滚动。