2

TableRow マージンについて多くの解決策を見つけましたが、行を試してみるとまったくマージンがありません。

これは私のコードです:

        TableLayout table = (TableLayout)findViewById(R.id.myTableLayout);

        for (int i = 0; i < 3; i++) {
            TableRow tr = new TableRow(this);
            LayoutParams layoutParams = new LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            int leftMargin=110;
            int topMargin=100;
            int rightMargin=100;
            int bottomMargin=100;
            layoutParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
            tr.setLayoutParams(layoutParams);
            tr.setBackgroundResource(R.drawable.shelf_bar);

            table.addView(tr, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT));
        }

これは私の期待される結果です:

ここに画像の説明を入力

誰か私の間違いを指摘してください。ありがとう

4

2 に答える 2

0

これを使うかもしれません

TableRow tr = new TableRow(this);  
TableLayout.LayoutParams tableRowParams=
  new TableLayout.LayoutParams
  (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.FILL_PARENT);

        int leftMargin=10;
        int topMargin=2;
        int rightMargin=10;
        int bottomMargin=2;

tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);

tr.setLayoutParams(tableRowParams);
于 2012-06-23T09:38:23.027 に答える