2012-09-18 52 views
1

我已经通过不同的例子,但我无法找到我的要求确切的答案。以下是我的代码。让我知道我错了哪里。setMargins()不工作tableRow设置边距

 TableLayout tableLayout = (TableLayout) findViewById(R.id.tableLayout); 
        TableRow tableRow = new TableRow(this); 
        TableLayout.LayoutParams params= 
           new TableLayout.LayoutParams 
           (TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.WRAP_CONTENT); 
        params.setMargins(20,20, 20, 5); 
        tableRow.setLayoutParams(params); 

tableLayout.addView(tableRow, new TableLayout.LayoutParams(
        LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); 

谢谢..,

+0

没有ü添加的TableRow您tableLayout ???? –

回答

2

当你让你的呼叫addView创建新LayoutParams并根据文档中关于addView

将带有指定布局参数子视图。

我认为你应该在你的addView通话发PARAMS而不是创建新的LayoutParams