ScrollView with TableLayout programmatically Java

别来无恙 提交于 2019-12-20 06:14:50

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/30005670/scrollview-with-tablelayout-programmatically-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!