TableRows在内容更改时更改大小

时间:2014-12-19 23:25:01

标签: android android-layout-weight

我正在尝试构建一个测验应用,每次我在TextView或Button中更改文本时,TableRows的相对大小都会发生变化。

我已将所有TableRow高度设置为0dp,并将所有封闭的视图高度设置为match_parent,但高度仍然会发生变化。

以下代码是我的布局(quiz.xml),我使用setContentView(R.layout.quiz)从活动中调用。

所有文本都以编程方式添加。 我正在使用Android IDE。

如何强制TableRows / Buttons / TextViews保持其高度(即使文本本身太大)?

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center"
    android:weightSum="1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="vertical"
    >

    <TableRow
        android:layout_weight="0.05"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginLeft="5sp"
        android:layout_marginRight="5sp"
        android:weightSum="1"
        >
        <Chronometer
            android:id="@+id/chrono"
            android:textSize="12sp"
            android:gravity="top|left"
            android:layout_weight="0.33"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
        />
        <TextView
            android:id="@+id/progress_text"
            android:textSize="12sp"
            android:gravity="top|center_horizontal"
            android:layout_weight="0.34"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
        />
        <TextView
            android:id="@+id/score_text"
            android:textSize="12sp"
            android:gravity="top|right"
            android:layout_weight="0.33"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
        />
    </TableRow>

    <TableRow
        android:layout_weight="0.15"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginLeft="5sp"
        android:layout_marginRight="5sp"
        >
        <TextView
            android:id="@+id/question_text"
            android:textSize="12sp"
            android:gravity="top|left"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
        />
    </TableRow>

    <TableRow
        android:layout_weight="0.1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        >
        <Button
            android:id="@+id/choice1"
            android:textSize="12sp"
            android:gravity="top|left"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
        />
    </TableRow>

    <TableRow
        android:layout_weight="0.1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        >
        <Button
            android:id="@+id/choice2"
            android:textSize="12sp"
            android:gravity="top|left"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
        />
    </TableRow>

    <TableRow
        android:layout_weight="0.1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        >
        <Button
            android:id="@+id/choice3"
            android:textSize="12sp"
            android:gravity="top|left"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
        />
    </TableRow>

    <TableRow
        android:layout_weight="0.1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        >
        <Button
            android:id="@+id/choice4"
            android:textSize="12sp"
            android:gravity="top|left"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
        />
    </TableRow>

    <TableRow
        android:layout_weight="0.1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        >
        <Button
            android:id="@+id/choice5"
            android:textSize="12sp"
            android:gravity="top|left"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
        />
    </TableRow>

    <TableRow
        android:layout_weight="0.3"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginLeft="5sp"
        android:layout_marginRight="5sp"
        >
        <TextView
            android:id="@+id/explanation_text"
            android:textSize="10sp"
            android:gravity="top|left"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent" 
            />
    </TableRow>

</TableLayout>

0 个答案:

没有答案