Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.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 水平冻结一个表列_Java_Android_Scroll_Tableview_Horizontalscrollview - Fatal编程技术网

Java 水平冻结一个表列

Java 水平冻结一个表列,java,android,scroll,tableview,horizontalscrollview,Java,Android,Scroll,Tableview,Horizontalscrollview,我有一个活动,其中我实现了一个tableview,tableview有一个标题和一个正文,表格可以水平和垂直滚动 这是活动的源代码: public class ReportListActivity extends Activity { TableLayout report_table; TableRow tr_data; int j = 0; @Override protected void onCreate(Bundle savedInstance

我有一个活动,其中我实现了一个tableview,tableview有一个标题和一个正文,表格可以水平和垂直滚动

这是活动的源代码:

public class ReportListActivity extends Activity {

    TableLayout report_table;
    TableRow tr_data;

    int j = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report_list);

        report_table=(TableLayout) findViewById(R.id.report_table);


        //---------------Table Header-----------------------------------------------
        TableRow tr_head = new TableRow(this);
        tr_head.setId(10);
        tr_head.setBackgroundColor(Color.GRAY);
        tr_head.setLayoutParams(new LayoutParams(
        LayoutParams.FILL_PARENT,
        LayoutParams.WRAP_CONTENT));


        TextView label_sr_no = new TextView(this);
        label_sr_no.setId(20);
        label_sr_no.setText("S.No.");
        label_sr_no.setTextColor(Color.WHITE);
        label_sr_no.setPadding(5,5,5,5);
        tr_head.addView(label_sr_no);// add the column to the table row here

        TextView label_test_name = new TextView(this);
        label_test_name.setId(21);// define id that must be unique
        label_test_name.setText("Test Name"); // set the text for the header 
        label_test_name.setTextColor(Color.WHITE); // set the color
        label_test_name.setPadding(5,5,5,5); // set the padding (if required)
        tr_head.addView(label_test_name); // add the column to the table row here

        TextView label_test_date = new TextView(this);
        label_test_date.setId(21);// define id that must be unique
        label_test_date.setText("Date"); // set the text for the header 
        label_test_date.setTextColor(Color.WHITE); // set the color
        label_test_date.setPadding(5,5,5,5); // set the padding (if required)
        tr_head.addView(label_test_date); // add the column to the table row here

        TextView label_ro = new TextView(this);
        label_ro.setId(21);// define id that must be unique
        label_ro.setText("R.O."); // set the text for the header 
        label_ro.setTextColor(Color.WHITE); // set the color
        label_ro.setPadding(5,5,5,5); // set the padding (if required)
        tr_head.addView(label_ro); // add the column to the table row here

        TextView label_wo = new TextView(this);
        label_wo.setId(21);// define id that must be unique
        label_wo.setText("W.O."); // set the text for the header 
        label_wo.setTextColor(Color.WHITE); // set the color
        label_wo.setPadding(5,5,5,5); // set the padding (if required)
        tr_head.addView(label_wo); // add the column to the table row here

        TextView label_lo = new TextView(this);
        label_lo.setId(21);// define id that must be unique
        label_lo.setText("L.O."); // set the text for the header 
        label_lo.setTextColor(Color.WHITE); // set the color
        label_lo.setPadding(5,5,5,5); // set the padding (if required)
        tr_head.addView(label_lo); // add the column to the table row here

        TextView label_max = new TextView(this);
        label_max.setId(21);// define id that must be unique
        label_max.setText("Max."); // set the text for the header 
        label_max.setTextColor(Color.WHITE); // set the color
        label_max.setPadding(5,5,5,5); // set the padding (if required)
        tr_head.addView(label_max); // add the column to the table row here

        TextView label_tm = new TextView(this);
        label_tm.setId(21);// define id that must be unique
        label_tm.setText("T.M."); // set the text for the header 
        label_tm.setTextColor(Color.WHITE); // set the color
        label_tm.setPadding(5,5,5,5); // set the padding (if required)
        tr_head.addView(label_tm); // add the column to the table row here

        TextView label_rank = new TextView(this);
        label_rank.setId(21);// define id that must be unique
        label_rank.setText("Rank"); // set the text for the header 
        label_rank.setTextColor(Color.WHITE); // set the color
        label_rank.setPadding(5,5,5,5); // set the padding (if required)
        tr_head.addView(label_rank); // add the column to the table row here

        report_table.addView(tr_head, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

      //---------------Table Header-----------------------------------------------



        //--------------------Table Body---------------------------
        for (int i=1; i<=10; i++)
        {
            tr_data = new TableRow(this);
            tr_data.setId(10);
            tr_data.setBackgroundColor(Color.TRANSPARENT);
            tr_data.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));


            final TextView sr_no = new TextView(this);
            sr_no.setId(20);
            sr_no.setText(""+i);
            sr_no.setTextColor(Color.BLACK);
            sr_no.setPadding(5,5,5,5);
            tr_data.addView(sr_no);// add the column to the table row here

            final TextView test_name = new TextView(this);
            test_name.setId(21);// define id that must be unique
            test_name.setText("Speed Test 60(min) Demo-ST-01"); // set the text for the header 
            test_name.setTextColor(Color.BLACK); // set the color
            test_name.setPadding(5,5,5,5); // set the padding (if required)
            tr_data.addView(test_name); // add the column to the table row here

            final TextView test_date = new TextView(this);
            test_date.setId(21);// define id that must be unique
            test_date.setText("12 Mar 2013"); // set the text for the header 
            test_date.setTextColor(Color.BLACK); // set the color
            test_date.setPadding(5,5,5,5); // set the padding (if required)
            tr_data.addView(test_date); // add the column to the table row here

            final TextView test_ro = new TextView(this);
            test_ro.setId(21);// define id that must be unique
            test_ro.setText("2"); // set the text for the header 
            test_ro.setTextColor(Color.BLACK); // set the color
            test_ro.setPadding(5,5,5,5); // set the padding (if required)
            tr_data.addView(test_ro); // add the column to the table row here

            final TextView test_wo = new TextView(this);
            test_wo.setId(21);// define id that must be unique
            test_wo.setText("3"); // set the text for the header 
            test_wo.setTextColor(Color.BLACK); // set the color
            test_wo.setPadding(5,5,5,5); // set the padding (if required)
            tr_data.addView(test_wo); // add the column to the table row here

            final TextView test_lo = new TextView(this);
            test_lo.setId(21);// define id that must be unique
            test_lo.setText("85"); // set the text for the header 
            test_lo.setTextColor(Color.BLACK); // set the color
            test_lo.setPadding(5,5,5,5); // set the padding (if required)
            tr_data.addView(test_lo); // add the column to the table row here

            final TextView test_max = new TextView(this);
            test_max.setId(21);// define id that must be unique
            test_max.setText("101"); // set the text for the header 
            test_max.setTextColor(Color.BLACK); // set the color
            test_max.setPadding(5,5,5,5); // set the padding (if required)
            tr_data.addView(test_max); // add the column to the table row here

            final TextView test_tm = new TextView(this);
            test_tm.setId(21);// define id that must be unique
            test_tm.setText("-1.5"); // set the text for the header 
            test_tm.setTextColor(Color.BLACK); // set the color
            test_tm.setPadding(5,5,5,5); // set the padding (if required)
            tr_data.addView(test_tm); // add the column to the table row here

            final TextView test_rank = new TextView(this);
            test_rank.setId(21);// define id that must be unique
            test_rank.setText("5810"); // set the text for the header 
            test_rank.setTextColor(Color.BLACK); // set the color
            test_rank.setPadding(5,5,5,5); // set the padding (if required)
            tr_data.addView(test_rank); // add the column to the table row here

            final TextView test_exam_set = new TextView(this);
            test_exam_set.setId(21);// define id that must be unique
            test_exam_set.setText("123456"); // set the text for the header
            test_exam_set.setTextSize((float) 0.01);
            test_exam_set.setTextColor(Color.TRANSPARENT); // set the color
            test_exam_set.setPadding(5,5,5,5); // set the padding (if required)
            tr_data.addView(test_exam_set); // add the column to the table row here



            report_table.addView(tr_data, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));


            //----------------------On click table row---------------------------------------

            tr_data.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub


//                  Toast.makeText(getApplicationContext(), test_name.getText().toString(), Toast.LENGTH_LONG).show();
//                  Toast.makeText(getApplicationContext(), test_date.getText().toString(), Toast.LENGTH_LONG).show();
//                  Toast.makeText(getApplicationContext(), sr_no.getText().toString(), Toast.LENGTH_LONG).show();
                    //Toast.makeText(getApplicationContext(), test_exam_set.getText().toString(), Toast.LENGTH_LONG).show();

                    Intent intent = new Intent(ReportListActivity.this, ReportListDetailsActivity.class);
                    finish();
                    ReportListActivity.this.startActivity(intent);
                }
            });
            //----------------------On click table row---------------------------------------



        }

      //--------------------Table Body---------------------------


    }
    //onclick device back button
    @Override
    public void onBackPressed() {
        // do something on back.

        Intent intent = new Intent(ReportListActivity.this, TakeTestActivity.class);
        finish();
        ReportListActivity.this.startActivity(intent);
        return;
    }


  //method to show toast message
        public void makeAToast(String str) {
            //yet to implement
            Toast toast = Toast.makeText(this,str, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ReportListActivity" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >

         <HorizontalScrollView
                    android:id="@+id/horizontalScrollView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TableLayout
                    android:shrinkColumns="0,1,2,3,4,5,6,7,8,9"
                    android:id="@+id/report_table" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="match_parent">

            </TableLayout>

        </RelativeLayout>
         </HorizontalScrollView>

    </ScrollView>

</RelativeLayout>
公共类ReportListActivity扩展活动{
表布局报告表;
TableRow tr_数据;
int j=0;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u report\u list);
report\u table=(TableLayout)findviewbyd(R.id.report\u table);
//---------------表头-----------------------------------------------
TableRow tr_head=新TableRow(本);
tru头setId(10);
tr_头.立根基色(颜色.灰色);
tr_head.setLayoutParams(新的LayoutParams(
LayoutParams.FILL\u父级,
LayoutParams.WRAP_内容);
文本视图标签号=新文本视图(本);
标签编号setId(20);
标签号setText(“S.N.”);
标签号为setTextColor(颜色为白色);
标签编号设置填充(5,5,5,5);
tr_head.addView(label_sr_no);//在此处将列添加到表行中
TextView标签\测试\名称=新的TextView(此);
label_test_name.setId(21);//定义必须唯一的id
label_test_name.setText(“test name”);//设置标题的文本
label_test_name.setTextColor(Color.WHITE);//设置颜色
label_test_name.setPadding(5,5,5,5);//设置填充(如果需要)
tr_head.addView(label_test_name);//在此处将列添加到表行中
TextView标签\测试\日期=新的TextView(此);
label_test_date.setId(21);//定义必须唯一的id
label_test_date.setText(“日期”);//设置标题的文本
label_test_date.setTextColor(Color.WHITE);//设置颜色
label_test_date.setPadding(5,5,5,5);//设置填充(如果需要)
tr_head.addView(label_test_date);//在此处将列添加到表行中
TextView label_ro=新的TextView(本);
label_ro.setId(21);//定义必须唯一的id
label_ro.setText(“R.O.”;//设置标题的文本
label_ro.setTextColor(Color.WHITE);//设置颜色
label_ro.setPadding(5,5,5,5);//设置填充(如果需要)
tr_head.addView(label_ro);//在此处将列添加到表行
TextView标签=新的TextView(本);
label_wo.setId(21);//定义必须唯一的id
label_wo.setText(“W.O.”;//设置标题的文本
label_wo.setTextColor(Color.WHITE);//设置颜色
label_wo.setPadding(5,5,5,5);//设置填充(如果需要)
tr_head.addView(label_wo);//在此处将列添加到表行
TextView label_lo=新的TextView(此);
label_lo.setId(21);//定义必须唯一的id
label_lo.setText(“L.O.”;//设置标题的文本
label_lo.setTextColor(Color.WHITE);//设置颜色
label_lo.setPadding(5,5,5,5);//设置填充(如果需要)
tr_head.addView(label_lo);//在此处将列添加到表行
TextView label_max=新的TextView(此);
label_max.setId(21);//定义必须唯一的id
label_max.setText(“max.”;//设置标题的文本
label_max.setTextColor(Color.WHITE);//设置颜色
label_max.setPadding(5,5,5,5);//设置填充(如果需要)
tr_head.addView(label_max);//在此处将列添加到表行
TextView label_tm=新的TextView(此);
label_tm.setId(21);//定义必须唯一的id
label_tm.setText(“T.M.”;//设置标题的文本
label_tm.setTextColor(Color.WHITE);//设置颜色
label_tm.setPadding(5,5,5,5);//设置填充(如果需要)
tr_head.addView(label_tm);//在此处将列添加到表行
TextView label_rank=新的TextView(此);
label_rank.setId(21);//定义必须唯一的id
label_rank.setText(“rank”);//设置标题的文本
label_rank.setTextColor(Color.WHITE);//设置颜色
label_rank.setPadding(5,5,5,5);//设置填充(如果需要)
tr_head.addView(label_rank);//在此处将列添加到表行
report_table.addView(tr_head,new TableLayout.LayoutParams(
LayoutParams.FILL\u父级,
LayoutParams.WRAP_内容);
//---------------表头-----------------------------------------------
//--------------------桌体---------------------------

对于(inti=1;i活动_main.xml

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TableLayout
                android:id="@+id/report_table1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:shrinkColumns="0" >

                <TableRow>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="5dip"
                        android:text="S.No" />
                </TableRow>
            </TableLayout>
        </RelativeLayout>
    </HorizontalScrollView>
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <HorizontalScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TableLayout
                android:id="@+id/report_table"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TableRow>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="5dip"
                        android:text="Test name" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="5dip"
                        android:text="Date" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="5dip"
                        android:text="R.O" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="5dip"
                        android:text="W.O" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="5dip"
                        android:text="L.O" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="5dip"
                        android:text="Max." />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="5dip"
                        android:text="T.M." />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="5dip"
                        android:text="Rank" />
                </TableRow>
            </TableLayout>
        </HorizontalScrollView>
    </ScrollView>
</LinearLayout>


MainActivity.java

公共类MainActivity扩展了活动{

TableLayout report_table, report_table1;
TableRow tr_data, tr_data1;

int j = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    report_table = (TableLayout) findViewById(R.id.report_table);
    report_table1 = (TableLayout) findViewById(R.id.report_table1);

    // ---------------Table
    // Header-----------------------------------------------
    TableRow tr_head = new TableRow(this);
    tr_head.setId(10);
    tr_head.setBackgroundColor(Color.GRAY);
    tr_head.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

    /*
     * TextView label_sr_no = new TextView(this); label_sr_no.setId(20);
     * label_sr_no.setText("S.No."); label_sr_no.setTextColor(Color.WHITE);
     * label_sr_no.setPadding(5,5,5,5); tr_head.addView(label_sr_no);// add
     * the column to the table row here
     * 
     * TextView label_test_name = new TextView(this);
     * label_test_name.setId(21);// define id that must be unique
     * label_test_name.setText("Test Name"); // set the text for the header
     * label_test_name.setTextColor(Color.WHITE); // set the color
     * label_test_name.setPadding(5,5,5,5); // set the padding (if required)
     * tr_head.addView(label_test_name); // add the column to the table row
     * here
     * 
     * TextView label_test_date = new TextView(this);
     * label_test_date.setId(21);// define id that must be unique
     * label_test_date.setText("Date"); // set the text for the header
     * label_test_date.setTextColor(Color.WHITE); // set the color
     * label_test_date.setPadding(5,5,5,5); // set the padding (if required)
     * tr_head.addView(label_test_date); // add the column to the table row
     * here
     * 
     * TextView label_ro = new TextView(this); label_ro.setId(21);// define
     * id that must be unique label_ro.setText("R.O."); // set the text for
     * the header label_ro.setTextColor(Color.WHITE); // set the color
     * label_ro.setPadding(5,5,5,5); // set the padding (if required)
     * tr_head.addView(label_ro); // add the column to the table row here
     * 
     * TextView label_wo = new TextView(this); label_wo.setId(21);// define
     * id that must be unique label_wo.setText("W.O."); // set the text for
     * the header label_wo.setTextColor(Color.WHITE); // set the color
     * label_wo.setPadding(5,5,5,5); // set the padding (if required)
     * tr_head.addView(label_wo); // add the column to the table row here
     * 
     * TextView label_lo = new TextView(this); label_lo.setId(21);// define
     * id that must be unique label_lo.setText("L.O."); // set the text for
     * the header label_lo.setTextColor(Color.WHITE); // set the color
     * label_lo.setPadding(5,5,5,5); // set the padding (if required)
     * tr_head.addView(label_lo); // add the column to the table row here
     * 
     * TextView label_max = new TextView(this); label_max.setId(21);//
     * define id that must be unique label_max.setText("Max."); // set the
     * text for the header label_max.setTextColor(Color.WHITE); // set the
     * color label_max.setPadding(5,5,5,5); // set the padding (if required)
     * tr_head.addView(label_max); // add the column to the table row here
     * 
     * TextView label_tm = new TextView(this); label_tm.setId(21);// define
     * id that must be unique label_tm.setText("T.M."); // set the text for
     * the header label_tm.setTextColor(Color.WHITE); // set the color
     * label_tm.setPadding(5,5,5,5); // set the padding (if required)
     * tr_head.addView(label_tm); // add the column to the table row here
     * 
     * TextView label_rank = new TextView(this); label_rank.setId(21);//
     * define id that must be unique label_rank.setText("Rank"); // set the
     * text for the header label_rank.setTextColor(Color.WHITE); // set the
     * color label_rank.setPadding(5,5,5,5); // set the padding (if
     * required) tr_head.addView(label_rank); // add the column to the table
     * row here
     * 
     * report_table.addView(tr_head, new TableLayout.LayoutParams(
     * LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
     */

    // ---------------Table
    // Header-----------------------------------------------

    // --------------------Table Body---------------------------
    for (int i = 1; i <= 15; i++) {
        tr_data = new TableRow(this);
        tr_data.setId(10);
        tr_data.setBackgroundColor(Color.TRANSPARENT);
        tr_data.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

        tr_data1 = new TableRow(this);
        tr_data1.setId(10);
        tr_data1.setBackgroundColor(Color.TRANSPARENT);
        tr_data1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

        final TextView sr_no = new TextView(this);
        sr_no.setId(20);
        sr_no.setText("" + i);
        sr_no.setTextColor(Color.BLACK);
        sr_no.setPadding(5, 5, 5, 5);
        tr_data1.addView(sr_no);// add the column to the table row here

        final TextView test_name = new TextView(this);
        test_name.setId(21);// define id that must be unique
        test_name.setText("Speed Test 60(min) Demo-ST-01"); // set the text
                                                            // for the
                                                            // header
        test_name.setTextColor(Color.BLACK); // set the color
        test_name.setPadding(5, 5, 5, 5); // set the padding (if required)
        tr_data.addView(test_name); // add the column to the table row here

        final TextView test_date = new TextView(this);
        test_date.setId(21);// define id that must be unique
        test_date.setText("12 Mar 2013"); // set the text for the header
        test_date.setTextColor(Color.BLACK); // set the color
        test_date.setPadding(5, 5, 5, 5); // set the padding (if required)
        tr_data.addView(test_date); // add the column to the table row here

        final TextView test_ro = new TextView(this);
        test_ro.setId(21);// define id that must be unique
        test_ro.setText("2"); // set the text for the header
        test_ro.setTextColor(Color.BLACK); // set the color
        test_ro.setPadding(5, 5, 5, 5); // set the padding (if required)
        tr_data.addView(test_ro); // add the column to the table row here

        final TextView test_wo = new TextView(this);
        test_wo.setId(21);// define id that must be unique
        test_wo.setText("3"); // set the text for the header
        test_wo.setTextColor(Color.BLACK); // set the color
        test_wo.setPadding(5, 5, 5, 5); // set the padding (if required)
        tr_data.addView(test_wo); // add the column to the table row here

        final TextView test_lo = new TextView(this);
        test_lo.setId(21);// define id that must be unique
        test_lo.setText("85"); // set the text for the header
        test_lo.setTextColor(Color.BLACK); // set the color
        test_lo.setPadding(5, 5, 5, 5); // set the padding (if required)
        tr_data.addView(test_lo); // add the column to the table row here

        final TextView test_max = new TextView(this);
        test_max.setId(21);// define id that must be unique
        test_max.setText("101"); // set the text for the header
        test_max.setTextColor(Color.BLACK); // set the color
        test_max.setPadding(5, 5, 5, 5); // set the padding (if required)
        tr_data.addView(test_max); // add the column to the table row here

        final TextView test_tm = new TextView(this);
        test_tm.setId(21);// define id that must be unique
        test_tm.setText("-1.5"); // set the text for the header
        test_tm.setTextColor(Color.BLACK); // set the color
        test_tm.setPadding(5, 5, 5, 5); // set the padding (if required)
        tr_data.addView(test_tm); // add the column to the table row here

        final TextView test_rank = new TextView(this);
        test_rank.setId(21);// define id that must be unique
        test_rank.setText("5810"); // set the text for the header
        test_rank.setTextColor(Color.BLACK); // set the color
        test_rank.setPadding(5, 5, 5, 5); // set the padding (if required)
        tr_data.addView(test_rank); // add the column to the table row here

        final TextView test_exam_set = new TextView(this);
        test_exam_set.setId(21);// define id that must be unique
        test_exam_set.setText("123456"); // set the text for the header
        test_exam_set.setTextSize((float) 0.01);
        test_exam_set.setTextColor(Color.TRANSPARENT); // set the color
        test_exam_set.setPadding(5, 5, 5, 5); // set the padding (if
                                                // required)
        tr_data.addView(test_exam_set); // add the column to the table row
                                        // here

        report_table.addView(tr_data, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

        report_table1.addView(tr_data1, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

        // ----------------------On click table
        // row---------------------------------------

        tr_data.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                // Toast.makeText(getApplicationContext(),
                // test_name.getText().toString(),
                // Toast.LENGTH_LONG).show();
                // Toast.makeText(getApplicationContext(),
                // test_date.getText().toString(),
                // Toast.LENGTH_LONG).show();
                // Toast.makeText(getApplicationContext(),
                // sr_no.getText().toString(), Toast.LENGTH_LONG).show();
                // Toast.makeText(getApplicationContext(),
                // test_exam_set.getText().toString(),
                // Toast.LENGTH_LONG).show();

                // Intent intent = new Intent(ReportListActivity.this,
                // ReportListDetailsActivity.class);
                // finish();
                // ReportListActivity.this.startActivity(intent);
            }
        });
        // ----------------------On click table
        // row---------------------------------------

    }

    // --------------------Table Body---------------------------

}

// onclick device back button
@Override
public void onBackPressed() {
    // do something on back.

    // Intent intent = new Intent(ReportListActivity.this,
    // TakeTestActivity.class);
    // finish();
    // ReportListActivity.this.startActivity(intent);
    return;
}

// method to show toast message
public void makeAToast(String str) {
    // yet to implement
    Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}
TableLayout报告表,报告表1;
TableRow tr_数据,tr_数据1;
int j=0;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
report\u table=(TableLayout)findviewbyd(R.id.report\u table);
报告\表1=(表布局)findViewById(R.id.report\表1);
//------表格
//标题-----------------------------------------------
TableRow tr_head=新TableRow(本);
tru头setId(10);
tr_头.立根基色(颜色.灰色);
tr_head.setLayoutParams(新的LayoutParams(LayoutParams.FILL_父级、,
LayoutParams.WRAP_内容);
/*
*文本视图标签号=新文本视图(本);标签号。
public class ReportListActivity extends Activity {

    TableLayout srno_table;
    TableRow srno_report_tr_data;

    TableLayout report_table;
    TableRow report_tr_data;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report_list);

        srno_table=(TableLayout) findViewById(R.id.srno_table);

        //---------------Serial no Table Header-----------------------------------------------
        TableRow srno_tr_head = new TableRow(this);
        srno_tr_head.setId(10);
        srno_tr_head.setBackgroundColor(Color.GRAY);
        srno_tr_head.setLayoutParams(new LayoutParams(
        LayoutParams.FILL_PARENT,
        LayoutParams.WRAP_CONTENT));


        TextView label_sr_no = new TextView(this);
        label_sr_no.setId(20);
        label_sr_no.setText("S.No.");
        label_sr_no.setTextColor(Color.WHITE);
        label_sr_no.setPadding(5,5,5,5);
        srno_tr_head.addView(label_sr_no);// add the column to the table row here
        label_sr_no.setTextSize(20);    



        srno_table.addView(srno_tr_head, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

      //---------------Serial no Table Header-----------------------------------------------

        report_table=(TableLayout) findViewById(R.id.report_table);

        //---------------report Table Header-----------------------------------------------
        TableRow report_tr_head = new TableRow(this);
        report_tr_head.setId(10);
        report_tr_head.setBackgroundColor(Color.GRAY);
        report_tr_head.setLayoutParams(new LayoutParams(
        LayoutParams.FILL_PARENT,
        LayoutParams.WRAP_CONTENT));


        TextView label_test_name = new TextView(this);
        label_test_name.setId(20);
        label_test_name.setText("Test Name");
        label_test_name.setTextColor(Color.WHITE);
        label_test_name.setPadding(5,5,5,5);
        report_tr_head.addView(label_test_name);// add the column to the table row here
        label_test_name.setTextSize(20);    

        TextView label_test_date = new TextView(this);
        label_test_date.setId(21);// define id that must be unique
        label_test_date.setText("Date"); // set the text for the header 
        label_test_date.setTextColor(Color.WHITE); // set the color
        label_test_date.setPadding(5,5,5,5); // set the padding (if required)
        report_tr_head.addView(label_test_date); // add the column to the table row here
        label_test_date.setTextSize(20);

        TextView label_ro = new TextView(this);
        label_ro.setId(21);// define id that must be unique
        label_ro.setText("R.O."); // set the text for the header 
        label_ro.setTextColor(Color.WHITE); // set the color
        label_ro.setPadding(5,5,5,5); // set the padding (if required)
        report_tr_head.addView(label_ro); // add the column to the table row here
        label_ro.setTextSize(20);

        TextView label_wo = new TextView(this);
        label_wo.setId(21);// define id that must be unique
        label_wo.setText("W.O."); // set the text for the header 
        label_wo.setTextColor(Color.WHITE); // set the color
        label_wo.setPadding(5,5,5,5); // set the padding (if required)
        report_tr_head.addView(label_wo); // add the column to the table row here
        label_wo.setTextSize(20);

        TextView label_lo = new TextView(this);
        label_lo.setId(21);// define id that must be unique
        label_lo.setText("L.O."); // set the text for the header 
        label_lo.setTextColor(Color.WHITE); // set the color
        label_lo.setPadding(5,5,5,5); // set the padding (if required)
        report_tr_head.addView(label_lo); // add the column to the table row here
        label_lo.setTextSize(20);

        TextView label_max = new TextView(this);
        label_max.setId(21);// define id that must be unique
        label_max.setText("Max."); // set the text for the header 
        label_max.setTextColor(Color.WHITE); // set the color
        label_max.setPadding(5,5,5,5); // set the padding (if required)
        report_tr_head.addView(label_max); // add the column to the table row here
        label_max.setTextSize(20);

        TextView label_tm = new TextView(this);
        label_tm.setId(21);// define id that must be unique
        label_tm.setText("T.M."); // set the text for the header 
        label_tm.setTextColor(Color.WHITE); // set the color
        label_tm.setPadding(5,5,5,5); // set the padding (if required)
        report_tr_head.addView(label_tm); // add the column to the table row here
        label_tm.setTextSize(20);

        TextView label_rank = new TextView(this);
        label_rank.setId(21);// define id that must be unique
        label_rank.setText("Rank"); // set the text for the header 
        label_rank.setTextColor(Color.WHITE); // set the color
        label_rank.setPadding(5,5,5,5); // set the padding (if required)
        report_tr_head.addView(label_rank); // add the column to the table row here
        label_rank.setTextSize(20);


        report_table.addView(report_tr_head, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

      //---------------Serial no Table Header-----------------------------------------------



        //--------------------Sr No Table Body---------------------------
        for (int i=1; i<=10; i++)
        {
            srno_report_tr_data = new TableRow(this);
            srno_report_tr_data.setId(10);
            srno_report_tr_data.setBackgroundColor(Color.TRANSPARENT);
            srno_report_tr_data.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));


            final TextView sr_no = new TextView(this);
            sr_no.setId(20);
            sr_no.setText(""+i);
            sr_no.setTextColor(Color.BLACK);
            sr_no.setPadding(5,5,5,5);
            srno_report_tr_data.addView(sr_no);// add the column to the table row here





            srno_table.addView(srno_report_tr_data, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));


            //----------------------On click table row---------------------------------------

            srno_report_tr_data.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub


//                  Toast.makeText(getApplicationContext(), test_name.getText().toString(), Toast.LENGTH_LONG).show();
//                  Toast.makeText(getApplicationContext(), test_date.getText().toString(), Toast.LENGTH_LONG).show();
//                  Toast.makeText(getApplicationContext(), sr_no.getText().toString(), Toast.LENGTH_LONG).show();
                    //Toast.makeText(getApplicationContext(), test_exam_set.getText().toString(), Toast.LENGTH_LONG).show();

//                  Intent intent = new Intent(ReportListActivity.this, ReportListDetailsActivity.class);
//                  finish();
//                  ReportListActivity.this.startActivity(intent);
                }
            });
            //----------------------On click table row---------------------------------------



        }

      //--------------------Sr No Table Body Table Body---------------------------





        //=================Report table body============================


        for (int i=1; i<=10; i++)
        {
            report_tr_data=new TableRow(this);
            report_tr_data.setId(10);
            report_tr_data.setBackgroundColor(Color.TRANSPARENT);
            report_tr_data.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

            final TextView test_name = new TextView(this);
            test_name.setId(20);
            test_name.setText("Speed Test 60(min) Demo-ST-01");
            test_name.setTextColor(Color.BLACK);
            test_name.setPadding(5,5,5,5);
            report_tr_data.addView(test_name);// add the column to the table row here

            final TextView test_date = new TextView(this);
            test_date.setId(21);// define id that must be unique
            test_date.setText("12 Mar 2013"); // set the text for the header 
            test_date.setTextColor(Color.BLACK); // set the color
            test_date.setPadding(5,5,5,5); // set the padding (if required)
            report_tr_data.addView(test_date); // add the column to the table row here

            final TextView test_ro = new TextView(this);
            test_ro.setId(21);// define id that must be unique
            test_ro.setText("2"); // set the text for the header 
            test_ro.setTextColor(Color.BLACK); // set the color
            test_ro.setPadding(5,5,5,5); // set the padding (if required)
            report_tr_data.addView(test_ro); // add the column to the table row here

            final TextView test_wo = new TextView(this);
            test_wo.setId(21);// define id that must be unique
            test_wo.setText("3"); // set the text for the header 
            test_wo.setTextColor(Color.BLACK); // set the color
            test_wo.setPadding(5,5,5,5); // set the padding (if required)
            report_tr_data.addView(test_wo); // add the column to the table row here

            final TextView test_lo = new TextView(this);
            test_lo.setId(21);// define id that must be unique
            test_lo.setText("85"); // set the text for the header 
            test_lo.setTextColor(Color.BLACK); // set the color
            test_lo.setPadding(5,5,5,5); // set the padding (if required)
            report_tr_data.addView(test_lo); // add the column to the table row here

            final TextView test_max = new TextView(this);
            test_max.setId(21);// define id that must be unique
            test_max.setText("101"); // set the text for the header 
            test_max.setTextColor(Color.BLACK); // set the color
            test_max.setPadding(5,5,5,5); // set the padding (if required)
            report_tr_data.addView(test_max); // add the column to the table row here

            final TextView test_tm = new TextView(this);
            test_tm.setId(21);// define id that must be unique
            test_tm.setText("-1.5"); // set the text for the header 
            test_tm.setTextColor(Color.BLACK); // set the color
            test_tm.setPadding(5,5,5,5); // set the padding (if required)
            report_tr_data.addView(test_tm); // add the column to the table row here

            final TextView test_rank = new TextView(this);
            test_rank.setId(21);// define id that must be unique
            test_rank.setText("5810"); // set the text for the header 
            test_rank.setTextColor(Color.BLACK); // set the color
            test_rank.setPadding(5,5,5,5); // set the padding (if required)
            report_tr_data.addView(test_rank); // add the column to the table row here

            final TextView test_exam_set = new TextView(this);
            test_exam_set.setId(21);// define id that must be unique
            test_exam_set.setText("123456"); // set the text for the header
            test_exam_set.setTextSize((float) 0.01);
            test_exam_set.setTextColor(Color.TRANSPARENT); // set the color
            test_exam_set.setPadding(5,5,5,5); // set the padding (if required)
            report_tr_data.addView(test_exam_set); // add the column to the table row here

            report_table.addView(report_tr_data, new TableLayout.LayoutParams(
                     LayoutParams.FILL_PARENT,
                     LayoutParams.WRAP_CONTENT));



//----------------------On click table row---------------------------------------

            report_tr_data.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub


                    Toast.makeText(getApplicationContext(), test_name.getText().toString(), Toast.LENGTH_LONG).show();
//                  Toast.makeText(getApplicationContext(), test_date.getText().toString(), Toast.LENGTH_LONG).show();
//                  Toast.makeText(getApplicationContext(), sr_no.getText().toString(), Toast.LENGTH_LONG).show();
                    Toast.makeText(getApplicationContext(), test_exam_set.getText().toString(), Toast.LENGTH_LONG).show();

//                  Intent intent = new Intent(ReportListActivity.this, ReportListDetailsActivity.class);
//                  finish();
//                  ReportListActivity.this.startActivity(intent);
                }
            });
            //----------------------On click table row---------------------------------------

        }


      //=================Report table body============================





    }
    //onclick device back button
    @Override
    public void onBackPressed() {
        // do something on back.

        Intent intent = new Intent(ReportListActivity.this, TakeTestActivity.class);
        finish();
        ReportListActivity.this.startActivity(intent);
        return;
    }


  //method to show toast message
        public void makeAToast(String str) {
            //yet to implement
            Toast toast = Toast.makeText(this,str, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ReportListActivity" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <RelativeLayout
                android:id="@+id/relativeLayout1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true" >

                <TableLayout
                    android:id="@+id/srno_table"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true" >
                </TableLayout>
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/relativeLayout1" >
                <HorizontalScrollView
                android:id="@+id/horizontalScrollView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/relativeLayout1" >

                    <TableLayout
                        android:id="@+id/report_table"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >


                    </TableLayout>

            </HorizontalScrollView>
            </RelativeLayout>



        </RelativeLayout>

    </ScrollView>

</RelativeLayout>