EditText没有在TableLayout中调整大小

时间:2014-09-18 09:31:50

标签: java android fragment tablelayout

我在Fragment中有以下TableLayout,其中EditTexts的标题行被禁用(纯粹用于美化目的,即使对于TextViews,结果也相同):

    <TableLayout
            android:id="@+id/table_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:stretchColumns="*" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <EditText
                    android:id="@+id/table_header_bsight"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cell_shape"
                    android:focusable="false"
                    android:gravity="center|center_horizontal"
                    android:paddingBottom="5dp"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="5dp"
                    android:text="@string/table_heading_bs"
                    android:textColor="#000"
                    android:textSize="18dp" >

                </EditText>

                //8 More EditTexts defined the same as above

然后,用户使用按钮在代码中使用以下内容将其他TableRows添加到TableLayout。

TableRow row = new TableRow(getActivity());
for (int i = 0; i < 9; i++) {
    EditText cell = new EditText(getActivity());
    cell.setPadding(30, 15, 30, 15);
    cell.setTextColor(Color.BLACK);
    cell.setBackgroundResource(R.drawable.cell_shape);
    cell.setGravity(Gravity.CENTER);
    // set up the keyboard so it doesn't go fullscreen
    cell.setImeOptions(EditorInfo.IME_ACTION_DONE);
    cell.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    cell.setInputType(InputType.TYPE_CLASS_NUMBER
            | InputType.TYPE_NUMBER_FLAG_DECIMAL
            | InputType.TYPE_NUMBER_FLAG_SIGNED);
    row.addView(cell);
    table.addView(row);

问题是我在XML中定义的editTexts在输入长文本时没有调整大小,如下图所示。

See top row with "Remark"]![See top row with "Remark

我不知道如何通过在代码或XML中声明EditTexts来获得两个不同的结果。 任何人都能解释为什么他们会有不同的行为吗?

0 个答案:

没有答案