<TableLayout android:layout_width="wrap_content" |
02 | android:layout_height="wrap_content" android:stretchColumns="*" |
03 | android:background="#ff0000"> |
04 | <TableRow android:layout_margin="1dp"> |
05 | <TextView android:text="first column" android:background="#000000" |
06 | android:layout_margin="1dp" /> |
07 | <TextView android:text="second column" android:background="#000000" |
08 | android:layout_margin="1dp" /> |
09 | </TableRow> |
10 | ... |
11 |
|
위 코드처럼 테이블레이아웃에 배경을 주고 tr에는 마진을 주고 텍스트뷰에 다시 배경색을 줘서 테이블의 라인을 그리려고 하는데..
데이터가 동적이라서 tr을 for문을 돌리고 있는데..
코드상에서 tablerow에 margin을 주는데.. 실제로 xml에서는 잘 나타나지는 라인이 코드로 해볼때는 나타나지 않는거로 봐서.. 코드상의 문제인거 같은데..
자바코드로 어떻게 나타내야 할까요??
아래 코드에서 잘못된 부분이 멀까요..
tl = (TableLayout)findViewById(R.id.testLogTable);
// TODO Auto-generated method stub
String[] tableArray = {"1111","222222222222","3333333333333333333333333333333333333333333"};
for (int j=0; j<3; j++) {
TableLayout.LayoutParams mlp = new TableLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mlp.setMargins(3,3,3,3);
// table.setLayoutParams(mlp);
// tl.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TableRow tr = new TableRow(TestActivity.this);
TableRow.LayoutParams trp = new TableRow.LayoutParams(new ViewGroup.MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
trp.setMargins(5, 5, 5, 5);
tr.setLayoutParams(trp);
// if(j%2==0){
// tr.setBackgroundColor(Color.rgb(182,202,234));
// }else{
// tr.setBackgroundColor(Color.WHITE);
// }
for (int i=0; i<3; i++) {
TextView tv = new TextView(TestActivity.this);
// tv.setLayoutParams(new ViewGroup.MarginLayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tv.setText(tableArray[i]);
tv.setPadding(10,10,10,10);
tv.setBackgroundColor(Color.BLACK);
// params.setMargins( 2, 2, 2, 2 );
// tv.setLayoutParams( params );
tr.addView(tv);
}
tl.addView(tr,mlp);
}




우와~~ 좋은 정보 감사해요. 막혀 있던 문제가 빵~~~ 뚫렸어요!