【发布时间】:2011-01-18 13:18:14
【问题描述】:
我正在尝试使用 imageview 和 textview 创建一个动态行。 像这样的:
|_| textview
所以我的问题是,是否有可能在同一行中,在 java 源代码中的 imageview 附近有一个 textview,而不使用 xml 文件..
这是我的代码:
TableLayout table = (TableLayout)findViewById(R.id.table);
db.open();
Cursor c5 = db.getAllCodes();
if (c5.moveToFirst())
{
do{
//rows
TableRow tr = new TableRow(this);
tr.setClickable(true);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
TextView title = new TextView(this);
title.setTextColor(Color.BLACK);
title.setTextSize(20);
//TextView text = new TextView(this);
//TextView stamp = new TextView(this);
title.setText(c5.getString(6));
//text.setText(c5.getString(1));
//stamp.setText(c5.getString(2));
//tr.addView(iv);
tr.addView(title);
//tr.addView(text);
//tr.addView(stamp);
//add row to layout
getLayoutInflater().inflate(R.layout.image, table, true);
table.addView(tr,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
while (c5.moveToNext());}
db.close();
这段代码的结果是创建了两个不同的行,一个是图像,一个是文本视图。
【问题讨论】:
标签: android dynamic android-tablelayout