hi i’ve tried to add margin programmatically
i’ve tried using
TextView tv = new TextView(this);
LayoutParams params = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
params.setMargins(100, 20, 0, 0);
layout.addView(tv, params);
which uses android.widget.LinearLayout.LayoutParams, but because of the table, i got runtime error for it.
how should i do it then ?
this is my code :
//create table row
TableRow trA = new TableRow(this);
trA.setId(1000+i);
trA.setLayoutParams(new LayoutParams (LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
//add data to table row
TextView tvA = new TextView (this);
tvA.setId(2000+i);
tvA.setText(aList.get(i).toString());
tvA.setTextSize(18);
tvA.setTextColor(Color.BLACK);
tvA.setClickable(true);
tvA.setOnClickListener(this);
tvA.setSingleLine(false);
tvA.setHorizontallyScrolling(false);
tvA.setWidth(0);
tvA.setHeight(100);
trA.addView(tvA);
tableA.addView(trA,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
== edited with import android.widget.TableLayout.LayoutParams; ==
i added this at the end where i declare the tablerow
LayoutParams params = new LayoutParams (LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 20);
and edited the addView at tableA
tableA.addView(tvA, params);
i have error in the log cat, it display quite alot, so i gave the main one here : The specified child already has a parent. You must call removeView() on the child’s parent first.
1 Answer