1

I Displayed my program's output via TableRow in TableLayout using array of Textview.Actually the output is of 2d array. I displayed every element of 2d array without any problems. But what the problem is I cant have space between TextViews(Columns). Below is the image which explains this clearly.I want to do this programmatically

enter image description here

Please help me to solve this

Kiruba Karan
  • 39
  • 1
  • 11

2 Answers2

1

Remember that almost any property that can be set on your XML layout, can also be set programmatically!

The way to do it is:

view.setPadding(0,padding,0,0);

This will set the top padding to padding-pixels. If you want to set it in dp instead, you can do a conversion:

float scale = getResources().getDisplayMetrics().density;
int dpAsPixels = (int) (sizeInDp*scale + 0.5f);

I go this from here .

Community
  • 1
  • 1
Merlevede
  • 8,140
  • 1
  • 24
  • 39
0

You can set padding programmatically on the textview by using this method:

txt.setPadding(left, top, right, bottom);

set integer value for left,top,right,bottom according to your condition.Hope it will help...

userAndroid
  • 586
  • 2
  • 9
  • 26