안드로이드 개발 질문/답변
(글 수 45,052)
스도쿠를 만드는 도중 9*9배열을 만들고 나서 버튼에 배치하고 싶은데
TableLayout 으로 가로세로 맞추는 곳에서 막혔습니다.
//문제의 답 배열
int [][] mainArr = new int[9][9];
mainArr = sdokuArrSet(mainArr);
final int [][] FArr = mainArr;
TableLayout root = new TableLayout(this);
TableLayout.LayoutParams parms = new TableLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT,
0.0F
);
parms.setMargins(1, 1, 0, 0);
// 버튼을 배열로 배치,숫자 세팅
for(int i=0;i<FArr.length;i++){
TableRow tr = new TableRow(this);
for(int j=0;j<FArr[i].length;j++ ){
//버튼생성
Button button = new Button(this);
RelativeLayout.LayoutParams buttonParams = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
buttonParams.addRule(9);
button.setLayoutParams(buttonParams);
button.setText(FArr[i][j]+"");
button.setWidth(30);
button.setHeight(15);
tr.addView(button);
}
root.addView(tr);
}
setContentView(root);
}
xml 파일은 사용하지 않습니다.
root 가 레이아웃이라.
안드로이드 이틀째라 모르는 것이 많네요 ;;
에러메시지는 없으며 (적어도 콘솔에는)
에뮬레이터 실행시 검정 바탕만 나옵니다.
잘부탁드립니다.
환경
(
우분투 9.0.04
이클립스 갈릴레오
)
그리고 밑에 내용 참고하세요~
The children of a TableRow do not need to specify the
layout_width
andlayout_height
attributes in the XML file. TableRow always enforces those values to be respectivelyFILL_PARENT
andWRAP_CONTENT
.