Hey Guys,
So my problem is i have tried almost everything i can think of to
center a programitacally created table in a programitically created
layout.
I've tried all the usual layout params center setting but still
nothing:
Score List is a set of pairs of scores (Name, Score). I'm just looping
through and adding them to cells in a table and its always aligned
left when i run it.
ArrayList<Score> scoreList = new ArrayList<Score>();
public LinearLayout getHighScoresView(Context context) {
final RelativeLayout.LayoutParams layoutParams = new
RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
RelativeLayout relLay = new RelativeLayout(context);
LinearLayout linLay = new LinearLayout(context);
TableLayout td = new TableLayout(context);
TextView name;
TextView score;
TableRow tr;
TableLayout.LayoutParams lopForMainRow = new
TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
lopForMainRow.gravity = Gravity.CENTER_HORIZONTAL;
td.setLayoutParams(lopForMainRow);
for (int i = 0; i < scoreList.size(); i++) {
tr = new TableRow(context);
name = new TextView(context);
score = new TextView(context);
name.setText(scoreList.get(i).name);
score.setText(Integer.toString(scoreList.get(i).score));
tr.addView(name);
tr.addView(score);
td.addView(tr);
}
relLay.addView(td, lopForMainRow);
linLay.setOrientation(LinearLayout.HORIZONTAL);
linLay.addView(relLay);
linLay.setGravity(Gravity.CENTER);
return linLay;
}
Then i set the view by using
setContentView(getHighScoresView(this));
Any help would be great!!
Cheers
Aice
So my problem is i have tried almost everything i can think of to
center a programitacally created table in a programitically created
layout.
I've tried all the usual layout params center setting but still
nothing:
Score List is a set of pairs of scores (Name, Score). I'm just looping
through and adding them to cells in a table and its always aligned
left when i run it.
ArrayList<Score> scoreList = new ArrayList<Score>();
public LinearLayout getHighScoresView(Context context) {
final RelativeLayout.LayoutParams layoutParams = new
RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
RelativeLayout relLay = new RelativeLayout(context);
LinearLayout linLay = new LinearLayout(context);
TableLayout td = new TableLayout(context);
TextView name;
TextView score;
TableRow tr;
TableLayout.LayoutParams lopForMainRow = new
TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
lopForMainRow.gravity = Gravity.CENTER_HORIZONTAL;
td.setLayoutParams(lopForMainRow);
for (int i = 0; i < scoreList.size(); i++) {
tr = new TableRow(context);
name = new TextView(context);
score = new TextView(context);
name.setText(scoreList.get(i).name);
score.setText(Integer.toString(scoreList.get(i).score));
tr.addView(name);
tr.addView(score);
td.addView(tr);
}
relLay.addView(td, lopForMainRow);
linLay.setOrientation(LinearLayout.HORIZONTAL);
linLay.addView(relLay);
linLay.setGravity(Gravity.CENTER);
return linLay;
}
Then i set the view by using
setContentView(getHighScoresView(this));
Any help would be great!!
Cheers
Aice