Java 第一个TableRow未显示
我正在尝试创建TableLayout,但出现了一些错误: 第一个红色行中的数据应该位于第二个白色行中 以下是布局xml文件:Java 第一个TableRow未显示,java,android,tablelayout,tablerow,Java,Android,Tablelayout,Tablerow,我正在尝试创建TableLayout,但出现了一些错误: 第一个红色行中的数据应该位于第二个白色行中 以下是布局xml文件: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_pa
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="horizontal|vertical"
android:layout_weight="1"
android:background="#838080">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:id="@+id/myOtherTableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
></TableLayout>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000">
<TableLayout
android:id="@+id/myTableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical"
android:background="#FFFFFF"
>
</TableLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
代码如下:
Color c = new Color();
setContentView(R.layout.data_table_creater_activity);
android.widget.TableRow.LayoutParams params = new TableRow.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(10, 0, 2, 0);
rowFiller();
TableLayout TbL = (TableLayout) findViewById(R.id.myOtherTableLayout);
TableRow headerRowHead = new TableRow(this);
headerRowHead.setId(51);
headerRowHead.setBackgroundColor(c.rgb(241,26,41));
TextView header1 = new TextView(this);
header1.setText(Html.fromHtml("<u>Purchase_Order_Number</u>"));
header1.setLayoutParams(params);
headerRowHead.addView(header1);
TextView header2 = new TextView(this);
header2.setText(Html.fromHtml("<u>Vendor</u>"));
header2.setLayoutParams(params);
headerRowHead.addView(header2);
TextView header3 = new TextView(this);
header3.setText(Html.fromHtml("<u>Currency</u>"));
header3.setLayoutParams(params);
headerRowHead.addView(header3);
TextView header4 = new TextView(this);
header4.setText(Html.fromHtml("<u>Total_Price</u>"));
header4.setLayoutParams(params);
headerRowHead.addView(header4);
TbL.addView(headerRowHead, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
));
TableRow headerRowData = new TableRow(this);
headerRowData.setId(50);
headerRowData.setBackgroundColor(c.rgb(255,255,255));
TextView headerData1 = new TextView(this);
header1.setText("0350005000");
header1.setLayoutParams(params);
headerRowData.addView(headerData1);
TextView headerData2 = new TextView(this);
header2.setText("Vendor_A");
header2.setLayoutParams(params);
headerRowData.addView(headerData2);
TextView headerData3 = new TextView(this);
header3.setText("EUR");
header3.setLayoutParams(params);
headerRowData.addView(headerData3);
TextView headerData4 = new TextView(this);
header4.setText("44.60");
header4.setLayoutParams(params);
headerRowData.addView(headerData4);
TbL.addView(headerRowData, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
));
Color c=新颜色();
setContentView(R.layout.data\u table\u creater\u活动);
android.widget.TableRow.LayoutParams params=新建TableRow.LayoutParams(
LayoutParams.WRAP_内容,
LayoutParams.WRAP_内容);
参数设置边距(10,0,2,0);
行填充();
TableLayout TbL=(TableLayout)findviewbyd(R.id.myOtherTableLayout);
TableRow headerRowHead=新的TableRow(此);
头颅侧位(51);
头基色(c.rgb(241,26,41));
TextView header1=新的TextView(此);
header1.setText(Html.fromHtml(“采购订单号”);
标题1.设置布局参数(参数);
headerRowHead.addView(header1);
TextView header2=新的TextView(此);
header2.setText(Html.fromHtml(“供应商”));
标题2.设置布局参数(参数);
headerRowHead.addView(header2);
TextView header3=新的TextView(此);
header3.setText(Html.fromHtml(“货币”));
标题3.设置布局参数(参数);
headerRowHead.addView(header3);
TextView header4=新的TextView(此);
header4.setText(Html.fromHtml(“总价”);
标题4.设置布局参数(参数);
headerRowHead.addView(header4);
TbL.addView(headerRowHead,新建TableLayout.LayoutParams(
LayoutParams.WRAP_内容,
LayoutParams.WRAP_内容
));
TableRow headerRowData=新的TableRow(此);
headerRowData.setId(50);
headerRowData.setBackgroundColor(c.rgb(255255));
TextView headerData1=新的TextView(此);
标题1.setText(“0350005000”);
标题1.设置布局参数(参数);
headerRowData.addView(headerdata 1);
TextView headerData2=新的TextView(此);
标题2.setText(“供应商A”);
标题2.设置布局参数(参数);
headerRowData.addView(headerData2);
TextView headerData3=新的TextView(此);
标题3.setText(“欧元”);
标题3.设置布局参数(参数);
headerRowData.addView(headerData3);
TextView headerData4=新的TextView(此);
标题4.setText(“44.60”);
标题4.设置布局参数(参数);
headerRowData.addView(headerData4);
TbL.addView(headerRowData,新的TableLayout.LayoutParams(
LayoutParams.WRAP_内容,
LayoutParams.WRAP_内容
));
为什么不显示第一行的数据?为什么第二行的数据显示在第一行
使用header1.setText(Html.fromHtml(“*Text*”)代码>,在文本下面加下划线效果很好,如下面的TableLayout所示
TextView headerData1 = new TextView(this);
header1.setText("0350005000");
header1.setLayoutParams(params);
headerRowData.addView(headerData1);
TextView headerData2 = new TextView(this);
header2.setText("Vendor_A");
header2.setLayoutParams(params);
headerRowData.addView(headerData2);
TextView headerData3 = new TextView(this);
header3.setText("EUR");
header3.setLayoutParams(params);
headerRowData.addView(headerData3);
TextView headerData4 = new TextView(this);
header4.setText("44.60");
header4.setLayoutParams(params);
headerRowData.addView(headerData4);
您为headerData1、headerData2、headerData3添加了header3,而不是headerData3等等。请检查headerData4是否存在问题,hi AndroidRookie,如果您接受我的帮助作为答案,那就好了