Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

android - How can I add separating lines between my TableRows that are created programmatically?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...