如何根据最高栏设置高度?

时间:2014-02-01 19:42:30

标签: android xml android-layout

我使用tableLayout,并且我想将tableRow的高度设置为必须高,以便正确显示textViews(在linearLayout中)。目前,第二个textView没有正确显示(它根本不适合行)。 这是XML:

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/background">

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/stripe_background"
        android:gravity="right|center_vertical"
        android:paddingTop="@dimen/stripe_padding_buttons_top_bottom"
        android:paddingBottom="@dimen/stripe_padding_buttons_top_bottom"
        android:paddingLeft="@dimen/stripe_padding_sides"
        android:paddingRight="@dimen/stripe_padding_sides"
        android:layout_marginBottom="@dimen/stripe_margin_top_bottom">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_column="0"
            android:layout_weight="1"
            android:paddingRight="@dimen/stripe_padding_between_text_views"
            android:gravity="right|center_vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/settings_text_view_current_consumption_main"
                android:id="@+id/textViewCurrentConsumptionMain"
                android:textColor="@color/big_text"
                android:textSize="@dimen/small_text"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/settings_text_view_current_consumption_additional"
                android:id="@+id/textViewCurrentConsumptionAdditional"
                android:textColor="@color/small_text"/>

        </LinearLayout>

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/checkBox"
            android:layout_column="1"
            android:button="@drawable/check_box_custom"
            android:checked="true" />
    </TableRow>
</TableLayout>

为了使我的问题更清楚,这是图像中的问题。第二个textView显示不正确: enter image description here

1 个答案:

答案 0 :(得分:2)

LinearLayout和所有TextView的高度设为wrap_contentTableRow