textview的边距

时间:2014-01-03 16:05:40

标签: android

我想设置textview页边距,但以下代码无法显示tablerowtextview。怎么了?

TableLayout table = (TableLayout) layoutView.findViewById(R.id.tableLayout1);
table.setStretchAllColumns(true);

for (int i = 0; i < 3; i++) {
    TableRow tablerow = new TableRow(layoutView.getContext());
    for (int j = 0; j < 3; j++) {
        TextView testview = new TextView(layoutView.getContext());
        testview.setBackgroundColor(Color.rgb(255, 255, 255));
        testview.setTextAppearance(layoutView.getContext(), R.style.TextView_SearchContent);
        testview.setText("test");

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.setMargins(1, 1, 1, 1);
        testview.setLayoutParams(params);
        tablerow.addView(testview);
    }

    table.addView(tablerow, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}

0 个答案:

没有答案