[英]Initializing TableLayout in XML and programmatically filling it - Android (java)
[英]ScrollView with TableLayout programmatically Java
我已經嘗試了一切,但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();
您可以通過這種方式實現,並且在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.