如何在android中以编程方式增加表格布局中的表头高度

时间:2014-07-15 04:42:10

标签: android android-layout

我想更改Table标题高度,以便标题标题将分解为下一行而不是一行,因为标题足够大以显示如何更改高度

这是我的代码

private void buildHeaderTable() {

    tr_head.setId(10);
    tr_head.setBackgroundColor(Color.rgb(254, 153, 0));// Hex: #fe9900
    tr_head.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));

    String[] LabelArray = { "Select" , "Sr No.", "Stock Nm", "Order Qty.",
            "Warehouse Inv." };

    for (int i = 0; i < LabelArray.length; i++) {
        TextView label = new TextView(this);
        String tblHdr = "";
        if (LabelArray[i].equals("Select")) {
            tblHdr = "Select";
        } else if (LabelArray[i].equals("Sr No.")) {
            tblHdr = "#";
        } else if (LabelArray[i].equals("Stock Nm")) {
            tblHdr = "Stock Name";
        } else if (LabelArray[i].equals("Order Qty.")) {
            tblHdr = "Order Qty.";
        } else if (LabelArray[i].equals("Warehouse Inv.")) {
            tblHdr = "Wrh Inv.";
        }
        setHeaderValue(label, tblHdr, i);
    }

    tblOrdrPrdHdr.addView(tr_head, new TableLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, 500));

}

  private void setHeaderValue(TextView label, String tblHdr, int i) {
    int width = 0;
     if (tblHdr.equals("Select")) {
        tblHdr="";
        width = 50;
    } else if (tblHdr.equals("#")) {
        width = 30;
    } else if (tblHdr.equals("Stock Name")) {
        width = 120;
    } else if (tblHdr.equals("Order Qty.")) {
        width = 120;
    } else if (tblHdr.equals("Wrh Inv.")) {
        width = 120;
    }

    label.setId(i);
    label.setText(tblHdr);
    label.setTextColor(Color.WHITE);
    label.setPadding(5, 5, 5, 5);
    label.setWidth(width);
    label.setGravity(Gravity.LEFT);
    tr_head.addView(label);// add the column to the table row here

}

我在

更改了价值
tr_head.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT))<-----this line

但不适合身高。

1 个答案:

答案 0 :(得分:2)