How to set padding to columns in table layout dynamically

Posted by Praveenb on Stack Overflow See other posts from Stack Overflow or by Praveenb
Published on 2010-12-29T09:51:23Z Indexed on 2010/12/29 9:54 UTC
Read the original article Hit count: 295

Hi all,

I am trying to create a table layout with buttons dynamically. I am able to get the table layout with buttons. bt i need padding between buttons. How i can get programatically.

I tried following code bt

private void showCowsTblField()
{

    for (int row = 0; row < numberOfRowsInField-1; row++)
    {
        TableRow tableRow = new TableRow(this);  
        tableRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT ));
        for (int column = 0; column < numberOfColumnsInField -1; column++)
        {
            blocks[row][column].setLayoutParams(new LayoutParams(  
                    LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
            blocks[row][column].setPadding(blockPadding, blockPadding, blockPadding, blockPadding);

            tableRow.addView(blocks[row][column]);
            tableRow.setPadding(blockPadding, blockPadding, blockPadding, blockPadding);
        }
        tblCows.addView(tableRow,new TableLayout.LayoutParams(  
                LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));  
    }
}

Please let me know.... Thanks.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-layout