TableRow文字剪裁

时间:2012-07-19 00:24:56

标签: android android-layout

我有一个TableLayout,我将动态添加以下配置的表行。

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="4dp"
>

<TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/name"
                android:textAppearance="?android:attr/textAppearanceMedium" 
                android:gravity="left"/>

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/colon" 
                android:padding="10dip"/>

            <EditText
                android:id="@+id/add_server_name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:background="#FFBFCCCC"
                android:inputType="text"
                android:gravity="left"
                android:paddingLeft="5dp"/>
 </TableRow>

我使用添加表行的代码如下:

    TableLayout table = (TableLayout) findViewById(R.id.create_table);
    LayoutInflater inflater = getLayoutInflater();
    ArrayList<String> edit_test_items = getTextFields();
    if(edit_test_items!=null){
        for (String item : edit_test_items) {
            View row = inflater.inflate(R.layout.tbl_row_label_and_edittext,
                    table, false);
            TextView label = (TextView) row.findViewById(R.id.textView1);
            label.setText(item);

            EditText value = (EditText) row.findViewById(R.id.add_server_name);
            value.setTag(item);
            actTextVals.add(value);
            table.addView(row);
        }
    }

    ArrayList<String> spinner_items = getSpinnerFields();
    if(spinner_items!=null){
        for (String item : spinner_items) {
            View row = inflater.inflate(R.layout.tbl_row_label_and_spinner,
                    table, false);
            TextView label = (TextView) row.findViewById(R.id.textView4);
            label.setText(item);
            Spinner spinner = (Spinner) row.findViewById(R.id.group);
            spinner.setTag(item);
            adapter = getSpinnerDataArray(item);
            // ArrayAdapter.createFromResource(this,
            // R.array.groups_array,android.R.layout.simple_spinner_item);
            // set the appearance of widget items that show when open the widget
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            // set the adapter to spinner
            spinner.setAdapter(adapter);
            // set the action listener
            spinner.setOnItemSelectedListener(this);
            actSpinnerVals.add(spinner);
            table.addView(row);
        }
    }


    ArrayList<String> checkbox_items = getCheckBoxFields();
    if(checkbox_items!=null){
        for (String item : checkbox_items) {
            View row = inflater.inflate(R.layout.tbl_row_label_and_checkbox,
                    table, false);
            TextView label = (TextView) row.findViewById(R.id.textView4);
            label.setText(item);
            CheckBox checkBox = (CheckBox) row.findViewById(R.id.checkbox);
            checkBox.setTag(item);
            actCheckBoxVals.add(checkBox);
            table.addView(row);
        }
    }

现在当我在edit_test_items列表中只有大约4个项目时,我正在正确地呈现屏幕,但是当我在列表文本中有大约10个项目时,正在获取clPlease,找到下面的屏幕截图

2 个答案:

答案 0 :(得分:1)

尝试在TableLayout中设置android:shrinkColumns="1"

答案 1 :(得分:1)

我实际上弄明白了什么是错的。我的表布局在线性布局中。我将其更改为滚动视图,一切看起来都不错。