简体   繁体   中英

ScrollView with TableLayout programmatically Java

I have tried everything but my ScrollView doesn't work in my activity. I have activity where after user clicks button opens a table. I can't find a way that my table scrolls bouth ways. How can I make ScrollView programmatically? My code:

    TableLayout tableLayout = new TableLayout(getApplicationContext());
    tableLayout.setVerticalScrollBarEnabled(true);
    tableLayout.setBackgroundColor(Color.WHITE);
    TableRow tableRow;
    TextView textView,...
    tableRow = new TableRow(getApplicationContext());
    textView=new TextView(getApplicationContext());
    textView.setText("Date");
    textView.setTextColor(Color.BLACK);
    textView.setTypeface(null, Typeface.BOLD);
    textView.setPadding(20, 20, 20, 20);
    tableRow.addView(textView);
    tableLayout.addView(tableRow);
    for (Integer j = 0; j < count; j++)
    {
        tableRow = new TableRow(getApplicationContext());
        textView1 = new TextView(getApplicationContext());
        ....
   tableLayout.addView(tableRow);
        c.moveToNext() ;
    }
    c.close();
    setContentView(tableLayout);
    database.close();

You can make it this way and in ScrollView there must be only one child:

ScrollView scrollview = new ScrollView(context);
scrollview.setBackgroundColor(android.R.color.transparent);
scrollview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                                             LayoutParams.FILL_PARENT));
scrollview.addView(tableLayout);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM