Basically, I'm trying to develop an activity that creates "N" number of views, all evenly spaced out in a row. Problem is that whenever I do this only the last one appears. Just can't figure out what the problem is.

Main Code:


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Dimensions.setScreen(getWindowManager());

hideUI();
createLetterBoxes(5);
}

//Creates n boxes on the screen
private void createLetterBoxes(int n) {
RelativeLayout layout = new RelativeLayout(this);
layout.setBackgroundColor(Color.WHITE);

//Calculate the size of the padding
int padding = (Dimensions.WIDTH-(n*Dimensions.CARD_WIDTH))/(n+2);
Log.println(Log.ERROR, "", "" + padding);

//Create the layout
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(Dimensions.CARD_WIDTH, Dimensions.CARD_HEIGHT);
params.addRule(RelativeLayout.CENTER_VERTICAL);

setContentView(layout);

TextView[] views = new TextView[n];

//Create the views and assign data about them
int x = 0;
while(x<n) {
TextView tv;
ViewGroup.MarginLayoutParams marginParams;
tv = new TextView(this);
tv.setId(x);

tv.setLayoutParams(params);
marginParams = (ViewGroup.MarginLayoutParams) tv.getLayoutParams();
marginParams.leftMargin = padding*x + x*Dimensions.CARD_WIDTH;
Log.println(Log.ERROR, "", (padding * x + x * Dimensions.CARD_WIDTH) + "");
tv.setLayoutParams(marginParams);
tv.setBackgroundResource(R.drawable.letter_box);

tv.setOnClickListener(this);

views[x] = tv;
x++;
}

//Actually create the view
for(TextView current : views) {
Log.println(Log.ERROR, "", "" + current.getId());
layout.addView(current);
}

setContentView(layout);
}

Here's the code for Dimensions
 //General screen data
protected static int WIDTH;
protected static int HEIGHT;

//Attributes about letter cards
protected static int CARD_HEIGHT = 350;
protected static int CARD_WIDTH = 200;

//Sets the height and width based on the data given
protected static void setScreen(WindowManager manager) {
Display display = manager.getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics ();
display.getMetrics(outMetrics);

WIDTH = outMetrics.widthPixels;
HEIGHT = outMetrics.heightPixels;
}




Any help is appreciated! :)