编程设置边框的TableRow数组 [英] Programmatically set border for TableRow array

查看:219
本文介绍了编程设置边框的TableRow数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它是作为<一个同样的问题href=\"http://stackoverflow.com/questions/9216078/programmatically-set-border-for-tablerows-array\">here
但一直没有得到答复,所以我试着在这里,监守我需要它太:)结果
我得到了一个数组:(我shortend阵列/ code为SO)

 滚动型SV =新的滚动型(本);
TableLayout LL =新TableLayout(本);
Horizo​​ntalScrollView HSV =新Horizo​​ntalScrollView(本);
的TableRow tbrow =新的TableRow(本);
 的for(int i = 0; I&LT; mConnector.idArray.size();我++){
         tbrow =新的TableRow(本);
         tbrow.setLayoutParams(新TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,1));
         tbrow.setBackgroundColor(Color.rgb(51,51,51));         ll.addView(tbrow);
 }hsv.addView(Ⅱ);
sv.addView(HSV);
的setContentView(SV);

左明在Array的信息,我不认为你需要的。结果
但如何添加边框在每一行(preFER水平和垂直)?
我希望这是解决方案:

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

但它只是颜色我的整个表灰色。

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


解决方案

  

但如何添加边框在每一行(preFER水平和垂直)?
  我希望这是解决方案:


如果你只是想有周围的边框你的 TableRows 您可以简单地使用下面的绘制为背景的的TableRow

R.drawable.row_border

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android&GT;    [固体机器人:颜色=#FFFFFF/&GT;
    &LT;行程机器人:宽=3DP机器人:颜色=#99CC00/&GT;&LT; /形状&GT;

然后

  tbrow.setBackgroundResource(R.drawable.row_borders);

如果你想获得一定的宽度的边框,您可以使用,而不是一个图层列表有三个版本,一种为顶行,一个用于在行中部和一个用于底行

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);

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:

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>

then:

tbrow.setBackgroundResource(R.drawable.row_borders);

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屋!

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