Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: programmatically creating two columns in a table

showtimeTable = new TableLayout(this);
         showtimeTable.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

         for(int i=0;i<object.dateList.size();i++){
              /* Create a new row to be added. */
              TableRow tr = new TableRow(this);
              tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                   /* Create testview to be the row-content. */
              mytext = new TextView(this);
             mytext.setText(object.dateList.get(i).getTextDate());
             mytext.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
             mytext.setTextAppearance(this, R.style.detaileventDate);
                   tr.addView(mytext);



                   time = new TextView(this);
                   time.setText(object.dateList.get(i).getTime());
                   time.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
                   time.setTextAppearance(this, R.style.detaileventTime);
                    tr.addView(time);
         /* Add row to TableLayout. */
         showtimeTable.addView(tr,new TableLayout.LayoutParams(
                   LayoutParams.FILL_PARENT,
                   LayoutParams.WRAP_CONTENT));
         }


         layout.addView(showtimeTable);

I have this table all setup, but the two textfields are hugging each other. What I want to achieve is the appearance of two columns and have the time textfield on the right side.

I tried changing the margins in their respective Styles but that doesnt affect it.

like image 720
Adam Avatar asked Mar 12 '26 13:03

Adam


1 Answers

I think you should use padding here. It will make padding of the Text view inside the table row. I have tried to do it with your code and just added some test lines:

mytext.setPadding(20, 3, 20, 3);
time.setPadding(20, 3, 20, 3);

It worked fine. Moreover, you can use "Gravity" for your purposes. See and example here: http://developer.android.com/resources/tutorials/views/hello-tablelayout.html

like image 198
Belurd Avatar answered Mar 15 '26 02:03

Belurd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!