如何添加以编程方式创建我的TableRows之间的分隔线? [英] How can I add separating lines between my TableRows that are created programmatically?

查看:111
本文介绍了如何添加以编程方式创建我的TableRows之间的分隔线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序创建在Android项目TableLayout。我一直在只要有从数据库中读取更多的行添加TableRows。现在,我想补充隔离线,就像一个边框,TableRows之间。

在我,我创建了静态的XML我用了一个视图作为分隔符,风格,style.xml其他TableLayout。

我尝试添加一个视图来像这样的tablelayout:

 视图v =新的视图(本);
         v.setLayoutParams(新的LayoutParams(
                 LayoutParams.FILL_PARENT,
                 LayoutParams.WRAP_CONTENT));
         v.setBackgroundResource(R.drawable.rowseparator_shape);
             tr.addView(mTvDate);
             tr.addView(mTvResult);

             tl.addView(TR);
             tl.addView(五);
 

但只得到所有收集到的TableRows后添加一次。什么是添加一个查看每个TR加入的一个聪明的办法?或者我应该用别的产品总数?

解决方案

 视图v =新的视图(本);
v.setLayoutParams(新TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,1));
v.setBackgroundColor(Color.rgb(51,51,51));
tr.addView(mTvDate);
tr.addView(mTvResult);

tl.addView(TR);
tl.addView(五);
 

在这里,我要创建一个观点,即一个像素高,一个特定的背景色。这对我的作品。

I have a TableLayout that is created programmatically in an Android project. I keep adding TableRows as long as there are more rows fetched from the database. Now I want to add separating lines, like a border, between the TableRows.

In my other TableLayout that I created statically from XML I used a View as a separator, style with a style.xml.

I tried adding a View to the tablelayout like so:

View v=new View(this);
         v.setLayoutParams(new LayoutParams(
                 LayoutParams.FILL_PARENT,
                 LayoutParams.WRAP_CONTENT));
         v.setBackgroundResource(R.drawable.rowseparator_shape);
             tr.addView(mTvDate);
             tr.addView(mTvResult);

             tl.addView(tr); 
             tl.addView(v);

But it only gets added once after all the collected TableRows. What would be a smart way of adding one View for each tr added? Or should I use something else alltogether?

解决方案

View v = new View(this);
v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
v.setBackgroundColor(Color.rgb(51, 51, 51));
tr.addView(mTvDate);
tr.addView(mTvResult);

tl.addView(tr); 
tl.addView(v);

Here I'm creating a view that is one pixel high with a specific background color. This works for me.

这篇关于如何添加以编程方式创建我的TableRows之间的分隔线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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