user1079425
user1079425

Reputation:

No setPadding programmatically for TableRow?

I'm such new in Android and I would like to setPadding programmatically for a TableRow, I can have in my layout :

<TableRow
    android:padding="15dp" >

It looks that the Margin can be setted programmatically by setMargin however it looks that programmatically the TableRow object doesn't have a setPadding Method... Is there any method to set a padding to a tableRow programmatically ??

Thank you.

Upvotes: 3

Views: 3499

Answers (2)

Bryan Herbst
Bryan Herbst

Reputation: 67209

The TableRow class, as with all View subclasses, indeed has a setPadding method.

However, since you mention that you found setMargin, I believe you are looking at the TableRow.LayoutParams instead of the TableRow itself.

Margins are set in a View's LayoutParams, whereas padding is set on the View.

Upvotes: 3

macloving
macloving

Reputation: 1277

Yes, the TableRow object doesn't have a setMargin method. You can set margin to view via LayoutParams,as shown in the code below:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
params.setMargins(left,top,right,down);
tv1.setLayoutParams(params);

You can set padding for TableRow directly:

view.setPadding(left,top,right,down);

Upvotes: 0

Related Questions