滚动型与TableLayout的Java编程 [英] ScrollView with TableLayout programmatically Java

查看:269
本文介绍了滚动型与TableLayout的Java编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经试过一切,但我的滚动型并不在我的活动工作。我在那里用户点击后按钮会打开一个表活动。我不能找到一种方式,我的表滚动bouth方式。我怎样才能让滚动型编程?我的code:

  TableLayout tableLayout =新TableLayout(getApplicationContext());
    tableLayout.setVerticalScrollBarEnabled(真);
    tableLayout.setBackgroundColor(Color.WHITE);
    的TableRow的TableRow;
    TextView的TextView的,...
    的TableRow =新的TableRow(getApplicationContext());
    TextView中=新的TextView(getApplicationContext());
    textView.setText(日期);
    textView.setTextColor(Color.BLACK);
    textView.setTypeface(NULL,Typeface.BOLD);
    textView.setPadding(20,20,20,20);
    tableRow.addView(TextView的);
    tableLayout.addView(tablerow的);
    对于(整数j = 0; J<计数; J ++)
    {
        的TableRow =新的TableRow(getApplicationContext());
        textView1 =新的TextView(getApplicationContext());
        ....
   tableLayout.addView(tablerow的);
        c.moveToNext();
    }
    c.close();
    的setContentView(tableLayout);
    database.close();


解决方案

您可以把它这种方式,并在滚动型只能有一个孩子:

 滚动型滚动型=新的滚动型(上下文);
scrollview.setBackgroundColor(android.R.color.transparent);
scrollview.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,
                                             LayoutParams.FILL_PARENT));
scrollview.addView(tableLayout);

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

这篇关于滚动型与TableLayout的Java编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆