gpt4 book ai didi

android - 以编程方式为 TableRow 数组设置边框

转载 作者:太空宇宙 更新时间:2023-11-03 11:30:16 28 4
gpt4 key购买 nike

我知道这是与 here 相同的问题但它还没有收到答复,所以我在这里尝试一下,因为我也需要它:)
我有一个数组:(我缩短了 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);

遗漏了数组中的信息,我认为你不需要那个。
但是如何在每一行中添加边框(最好是水平和垂直)?我希望这是解决方案:

tbrow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
tbrow.setBackgroundColor(Color.rgb(51, 51, 51));

但它只会把我的整个 table 染成灰色。

希望我足够清楚,并希望他们是一个解决方案。

最佳答案

But how to add borders in every row (prefer horizontal and vertical)? I hoped this was the solution:

如果您只想在您的TableRows 周围设置边框,您可以简单地使用下面的drawable 作为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,一个用于顶行,一个用于中间行,一个用于底部行行。

关于android - 以编程方式为 TableRow 数组设置边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13511321/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com