我有 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);
上一篇:Apache的HttpClient的摘要式身份验证身份验证、摘要、Apache、HttpClient
下一篇:致命异常:主要java.lang.RuntimeException的:内容有鉴于与id属性“android.R.id.list”这不是一个ListView类是一个、属性、这不、异常