시작 버튼을 누르면, GridLayout내에 바둑판 형식으로 버튼을 배치하고자 합니다.
xml코드로 android:layout_Width="40dp" 이런식으로 주면 크기 조정이 되는데
java코드에서 btn.setWidth(40); 이와같이 설정해서 생성하면 크기가 제멋대로 나오네요...
현재 제가 짠 코드는 다음과 같습니다.
public class MainActivity extends AppCompatActivity {
int ix = 8;
int iy = 8;
int mine = 8;
Context context;
GridLayout manager;
LinearLayout mainLay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
mainLay = (LinearLayout) findViewById(R.id.MainLay);
manager = (GridLayout) findViewById(R.id.gameLay);
Button button = (Button)findViewById(R.id.btnStart);
}
public void btnStart_Click(View view) {
int num=1; //버튼 아이디 변수
for(int i=0; i<ix; i++)
{
for(int j=0; j<iy; j++)
{
Button btn = new Button(context);
btn.setId(num);
btn.setWidth(40);
btn.setHeight(40);
btn.setText("0");
manager.addView(btn);
num=num+1;
}
}
}
}
<GridLayout
android:id="@+id/gameLay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="8">
</GridLayout>
8000자 제한 때문에 xml파일 전체는 못올리네요 ㅠ 그리드뷰 코드만 올립니다.
레이아웃 때문에 몇일째 고생하네요.. 레이아웃만 어찌 해결하면 내부 java코드는 C#과 매우 흡사해서 할만할것같은데..
혹시 바둑판 모양으로 버튼을 생성하는데 있어서 더 알아야할 지식이나 설정이 더 있을까요??