以编程方式为 TableRow 数组设置边框 [英] Programmatically set border for TableRow array
问题描述
我知道这是与此处相同的问题但它还没有收到答复,所以我在这里尝试,因为我也需要它:)
我得到了一个数组:(我缩短了 SO 的数组/代码)
I know it is the same question as here
But it hasn't receive an answer yet, so I try it here, becuase I need it too :)
I got an Array: (I shortend the array/code for SO)
ScrollView sv = new ScrollView(this);
TableLayout ll=new TableLayout(this);
HorizontalScrollView hsv = new HorizontalScrollView(this);
TableRow tbrow=new TableRow(this);
for(int i=0;i<mConnector.idArray.size();i++) {
tbrow=new TableRow(this);
tbrow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
tbrow.setBackgroundColor(Color.rgb(51, 51, 51));
ll.addView(tbrow);
}
hsv.addView(ll);
sv.addView(hsv);
setContentView(sv);
省略了 Array 中的信息,我认为您不需要那个.
但是如何在每一行中添加边框(最好是水平和垂直)?我希望这是解决方案:
Left out the information in the Array, I don't think you need that.
But how to add borders in every row (prefer horizontal and vertical)?
I hoped this was the solution:
tbrow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
tbrow.setBackgroundColor(Color.rgb(51, 51, 51));
但它只是将我的整个桌子涂成灰色.
But it just colors my whole table grey.
希望我足够清楚,并希望他们是一个解决方案.
Hope I am clear enough, and hope their is a solution.
推荐答案
但是如何在每一行添加边框(最好是水平和垂直)?我希望这是解决方案:
But how to add borders in every row (prefer horizontal and vertical)? I hoped this was the solution:
如果您只想在 TableRows
周围设置边框,您可以简单地使用下面的可绘制对象作为 TableRow
的背景:
If you just want to have borders around your TableRows
you can simply use the drawable below as the background for the TableRow
:
R.drawable.row_border:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffffff" />
<stroke android:width="3dp" android:color="#99cc00" />
</shape>
然后:
tbrow.setBackgroundResource(R.drawable.row_borders);
如果你想获得一个等宽的边框,你可以用一个layer-list
代替三个版本,一个用于顶行,一个用于中间行,一个用于底部行.
If you want to obtain a constant width border, you can use instead a layer-list
with three versions, one for the top row, one for the rows in the middle and one for the bottom row.
这篇关于以编程方式为 TableRow 数组设置边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!