제가 자바코딩으로 레이아웃하다보니...


궁금한 점이 있습니다. 버튼을 코딩으로 넣었는데 


간격 조절이 되지 않습니다. 자바코딩으로 버튼의 간격조절을 할려고 하면 어떻게 해야하죠????



현재 xml에는 스크롤뷰만 하나 넣었습니다.


package ShowMing.testbtn;


import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

import android.view.ViewGroup.LayoutParams;

import android.widget.ImageButton;

import android.widget.LinearLayout;


public class Testbtn extends Activity implements View.OnClickListener {


private LinearLayout _LinearLayout = null;

private ImageButton[] btn = new ImageButton[40];

private LinearLayout _layout = null;

private LinearLayout.LayoutParams _params = null;

int a = 1;


@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_testbtn);


this._LinearLayout = (LinearLayout) findViewById(R.id.container);


this._params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,

LayoutParams.WRAP_CONTENT);


for (int i = 0; i < 10; i++) {


_layout = new LinearLayout(this);


for (int j = 1; j <= 3; j++) {


btn[a] = new ImageButton(this);

_layout.setLayoutParams(this._params);

btn[a].setImageResource(R.drawable.doo);

btn[a].setTag(a);

btn[a].setOnClickListener(this);

_layout.addView(btn[a]);

a++;

}


this._LinearLayout.addView(_layout);

}


}


@Override

public void onClick(View v) {

// TODO Auto-generated method stub

ImageButton newButton = (ImageButton) v;

for (ImageButton tempbtn : btn) {

if (tempbtn == newButton) {


newButton.setImageResource(R.drawable.ah);

int position = (Integer) v.getTag();


if (position % 3 != 0 && position % 3 != 1) {

btn[position - 1].setImageResource(R.drawable.ah);

btn[position + 1].setImageResource(R.drawable.ah);

btn[position - 3].setImageResource(R.drawable.ah);

btn[position + 3].setImageResource(R.drawable.ah);

}

}


}


}

}


버튼 간격이 한쪽으로 쏠려 있는데 이걸 균형있게 할려면 자바코드로 무엇을 사용해야되는지 궁금합니다.