编程设置保证金的TableRow [英] Programmatically set margin for TableRow
本文介绍了编程设置保证金的TableRow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 TableRows
在code动态创建的,我想设置页边距为这些 TableRows
。
I have TableRows
created dynamically in the code and I want to set margins for these TableRows
.
我的 TableRows
创建如下:
// Create a TableRow and give it an ID
TableRow tr = new TableRow(this);
tr.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
Button btnManageGroupsSubscriptions = new Button(this);
btnManageGroupsSubscriptions.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 40));
tr.addView(btnManageGroupsSubscriptions);
contactsManagementTable.addView(tr);
如何动态地设置页边距为这些?
How do I dynamically set the margins for these?
推荐答案
您必须设置的LayoutParams正常。保证金是布局的TableRow的属性,而不是,所以你必须设置所需的利润率在的LayoutParams。
You have to setup LayoutParams properly. Margin is a property of layout and not the TableRow , so you have to set the desired margins in the LayoutParams.
下面有一个样本code:
Heres a sample code:
TableRow tr = new TableRow(this);
TableLayout.LayoutParams tableRowParams=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin=10;
int topMargin=2;
int rightMargin=10;
int bottomMargin=2;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(tableRowParams);
这篇关于编程设置保证金的TableRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文