但し、TableRow.LayoutParams.setMargins(int left,int top, int right, int bottom)メソッド
を利用すれば、Activity自体の背景色とTableRowに表示するオブレクトの背景色を
変える事で枠線のように表示する事が可能です。
(setMarginsメソッドを利用する事でTableRowの上下左右に隙間を空ける事が可能になります)
下記にカレンダーアプリで日付毎の枠線を表示する為に利用したコードの一部を記載します。
TableLayout tableLayout = new TableLayout(this); setContentView(tableLayout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); TableRow tableRow; tableRow = new TableRow(this); TextView text = new TextView(this); TableRow.LayoutParams text_layout_params = new TableRow.LayoutParams(40,40); text_layout_params.setMargins(1, 1, 1, 1); //TableRowの上下左右にマージンを1空ける text.setLayoutParams(text_layout_params); //TextViewにLayoutParamsを設定 text.setTextSize(12); //表示テキストサイズ text.setWidth(40); //横幅 text.setGravity(Gravity.CENTER); //表示位置(中央) text.setBackgroundColor(Color.rgb(255,255,204)); //TextViewの背景色を設定 tableRow.addView(text,lp); //TextViewをサイズ指定で追加 tableLayout.addView(tableRow); //TableLayoutに行を追加
カレンダーアプリの実行結果
↑