本文介绍了通过tablerow问题设置缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code,它试图设置margin:

I have the following code, which tries to set the margin:

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

                          int leftMargin=20;
                          int topMargin=50;
                          int rightMargin=0;
                          int bottomMargin=50;

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

 TextView name = new TextView(this);
                          name.setText(Html.fromHtml(venues.get(j).name + "<br><br>" + venues.get(j).getFullAddress()));

然而,这不设置余量。我在做什么错在这里?

However this doesn't set the margin. What am I doing wrong here?

推荐答案

编辑。哎呀,我的坏,TableLayout.LayoutParams是罚款。上的TableRow的儿童使用TableRow.LayoutParams。

Edit. Whoops, my bad, TableLayout.LayoutParams is fine. Use TableRow.LayoutParams on the children of the TableRow.

我只是跑这个code(这是,在大多数情况下,你的code)和保证金套正确

I just ran this code (which is, for the most part, your code) and the margin sets correctly

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

    int leftMargin=100;
    int topMargin=50;
    int rightMargin=0;
    int bottomMargin=50;

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

    TextView tv = new TextView(this);
    tv.setText("EXAMPLE ROW");
    TableRow.LayoutParams textParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(textParams);
    tr.addView(tv);

    tlayout.addView(tr);

这篇关于通过tablerow问题设置缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:28