[英]ScrollView with TableLayout programmatically Java
I have tried everything but my ScrollView doesn't work in my activity. 我已经尝试了一切,但ScrollView在我的活动中无法正常工作。 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?
如何以编程方式制作ScrollView? 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 scrollview = new ScrollView(context);
scrollview.setBackgroundColor(android.R.color.transparent);
scrollview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
scrollview.addView(tableLayout);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.