[英]Android table layout how to set border programatically?
我正在以編程方式創建表布局,並顯示來自數據庫的數據。 每個單元格都是一個文本視圖。 我為每個文本視圖都給了邊框顏色黑色。這並沒有為表格布局創建完美的邊框。
我想要桌子的完美邊框。 如何以編程方式不使用任何xml文件來做到這一點。
我用來生成表格布局的代碼
TableLayout tableLayout = (TableLayout)findViewById(R.id.table);
final GradientDrawable gd = new GradientDrawable();
gd.setCornerRadius(5);
gd.setStroke(1, 0xFF000000);
TableRow tableRow = new TableRow(getApplicationContext());
TextView columsView = new TextView(getApplicationContext());
columsView.setBackgroundDrawable(gd);
columsView.setText(""+c3.getString(j));
columsView.setTextColor(Color.parseColor("#000000"));
tableRow.addView(columsView);
tableLayout.addView(tableRow);
當前輸出:檢查以下鏈接中的圖像
http://i.stack.imgur.com/gcmuI.jpg
桌子需要完美的邊框。我該如何編程?
您可以嘗試一下。
TableLayout.LayoutParams tableRowParams =
new TableLayout.LayoutParams
(TableLayout.LayoutParams.WrapContent, TableLayout.LayoutParams.WrapContent);
tableRowParams.SetMargins(3, 3, 2, 10);
row.LayoutParameters = tableRowParams;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.