【问题标题】:ScrollView with TableLayout programmatically Java带有 TableLayout 的 ScrollView 以编程方式 Java
【发布时间】:2015-07-12 09:28:45
【问题描述】:

我已经尝试了所有方法,但我的 ScrollView 在我的活动中不起作用。我有活动在用户单击按钮后打开一个表。我找不到我的表格双向滚动的方式。如何以编程方式制作 ScrollView?我的代码:

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

【问题讨论】:

    标签: java android scrollview tablelayout


    【解决方案1】:

    你可以这样做,ScrollView 必须只有一个孩子:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      • 2011-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多