[英]Android Table Cells Border
下面的xml代碼為我的表格單元格提供了適當的邊框
<TableRow android:background="#cdcdcd" >
<TextView android:text="1st Column" android:background="#ffffff" android:layout_margin="2dip"/>
<TextView android:text="2nd Column" android:background="#ffffff" android:layout_margin="2dip"/>
<TextView android:id="@+id/amount" android:background="#ffffff" android:layout_margin="2dip" android:text="3rd col"/>
</TableRow>
但是,當我嘗試以編程方式進行操作時,這是行不通的,這是我的代碼:
dataTable = (TableLayout)findViewById(R.id.data_table);
TableRow tr=new TableRow(this);
counter++;
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp.setMargins(2,2, 2, 2);
TextView tv= new TextView(this);
tv.setLayoutParams(lp);
tv.setText("text"+counter);
tv.setBackgroundColor(Color.parseColor("#ffffff"));
counter++;
TextView cb= new TextView(this);
cb.setLayoutParams(lp);
cb.setText("text"+counter);
counter++;
TextView ib= new TextView(this);
ib.setText("text"+counter);
ib.setLayoutParams(lp);
tr.setBackgroundColor(Color.parseColor("#cdcdcd"));
tr.setPadding(2, 2, 2, 2);
tr.addView(tv);
tr.addView(cb);
tr.addView(ib);
dataTable.addView(tr,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
除邊框和設置“ tv.setLayoutParams(lp);”外,所有其他東西都有效 該列的參數消失。
嘗試通過調用addView(View child,int index,ViewGroup.LayoutParams params)添加視圖
另外,嘗試為每個視圖創建一個新的LayoutParams實例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.