Position ImageButtons in RelativeLayout
<p>I am trying to program a menu for a game and now a want to make the level selection. It should have three rows with 5 buttons per row.</p>

<pre><code>for(int i=0; i&lt;3; ++i){
        for(int j=0; j&lt;5; ++j){
            ImageButton button = new ImageButton(this);

            RelativeLayout.LayoutParams paramsBut = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            paramsBut.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            paramsBut.addRule(RelativeLayout.ALIGN_PARENT_TOP);

            int marginLeft = (int)((float)(sizeLeftWidth/6) * (j+1)) + j*buttonSize;
            int marginTop = (int)((float)(sizeLeftHeight/4) * (i+1)) + i*buttonSize;
            paramsBut.leftMargin = marginLeft;
            paramsBut.topMargin = marginTop;

            button.setAdjustViewBounds(true);
            button.setMaxWidth(buttonSize);
            button.setMaxHeight(buttonSize);
            button.setBackgroundDrawable(null);

            Bitmap bmp = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.level),buttonSize,buttonSize,false);
            Drawable d = new BitmapDrawable(bmp);
            button.setImageDrawable(d);

            layout.addView(button,paramsBut);
        }
    }
</code></pre>

<p>RelativeLayout:</p>

<pre><code>RelativeLayout layout = new RelativeLayout(this);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    layout.setLayoutParams(params);
</code></pre>

<p>The problem is that the buttons are not at the right positions and I think the problem is with the margins.
Am I doing it right with the margins or is the whole code completely stupid? (I am always happy if I get hints how to improve my programming style ^^)</p>
