表中的多行未显示
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = null;
while (i < 5) {
TableRow trow = new TableRow(this);
while (j < 3) {
tv = new TextView(this);
tv.setText(" " + j + i);
tv.setTextColor(Color.BLACK);
tv.setWidth(25);
tv.setBackgroundColor(Color.WHITE);
trow.addView(tv);
j++;
}
Log.i("SS", "adding row for " + i + " time");
this.addContentView(trow, new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i++;
}
你好,我是安卓新手。 我想显示 5 行,每行有 3 个文本视图。这看起来很简单,但上面的代码不起作用。它只显示一行有 3 个文本视图。在 xml 中,我不使用表布局,行仅添加到线性布局。这是错误的吗?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = null;
while (i < 5) {
TableRow trow = new TableRow(this);
while (j < 3) {
tv = new TextView(this);
tv.setText(" " + j + i);
tv.setTextColor(Color.BLACK);
tv.setWidth(25);
tv.setBackgroundColor(Color.WHITE);
trow.addView(tv);
j++;
}
Log.i("SS", "adding row for " + i + " time");
this.addContentView(trow, new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i++;
}
Hi,i m new to android.
I want to show 5 rows with 3 textview each.It seems simple but the above code is not working.It shows only one row with 3 textviews.In xml i m not using table layout ,the rows are being added to a linear layout only.Is that wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将该行放入 tableLayout 中。
1) http://droidcake.com/2010/12/24/table-布局教程/
2) http://en.androidwiki.com/wiki/Dynamically_adding_rows_to_TableLayout
3) http://developerlife.com/tutorials/?p=307
一些需要遵循的教程。
You should put the row into the tableLayout.
1) http://droidcake.com/2010/12/24/table-layout-tutorial/
2) http://en.androidwiki.com/wiki/Dynamically_adding_rows_to_TableLayout
3) http://developerlife.com/tutorials/?p=307
few tutorial to follow.