1

I have searched google and stackoverflow thoroughly, but the only answer I get is: set each Tablerow with layout weight = "1". This doesnt work.

Now I have eight rows in a TableLayout, and each contains 5 LinearLayouts. Each of the LinearLayouts contains 2 TextViews, and the FontSizes vary from TextView to TextView.

It turns out that the TableRows vary in height, depending on the Fontsizes of the contained TextViews. Strangely enough, it doesnt have any impact on the layout whether I set the layout_height of the TableRows to "0dp" or to "match_parent" or "fill_parent".

How can I force the TableRows to have the same height? I dont want to use a specific pts value as height, because the tableRows must divide the whole screen equally between themselves.

Here is part of the xml, the actual file is huge:

<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>
4

1 回答 1

0

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

  • 确保所有元素共享相同的大小 - 话虽如此,不要担心整个表格,只需确保内部元素的尺寸相同
  • 或者简单地设置父布局的高度,不要让元素有所作为。这个解决方案的问题是,如果你在里面变大,你就会没有空间,所以你可能想坚持第一个选项
于 2013-02-28T14:21:32.127 回答