Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android表格单元格边框_Java_Android_Datatable_Android Tablelayout - Fatal编程技术网

Java Android表格单元格边框

Java Android表格单元格边框,java,android,datatable,android-tablelayout,Java,Android,Datatable,Android Tablelayout,下面的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"

下面的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>

除了边框和设置“tv.setLayoutParams(lp);”时,列中的参数将消失。

尝试通过调用 addView(视图子级、int索引、ViewGroup.LayoutParams参数)

另外,尝试为每个视图创建一个新的LayoutParams实例

    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));