如何动态绘制垂直线?

时间:2011-03-20 20:14:40

标签: android

我想要在表格行内动态绘制垂直线。 XML中的一些内容如下:

除了“视图”之外,我能够从代码中获取所有布局。任何建议将不胜感激!

<TableRow>
   <LinearLayout 
     ......
     android:orientation="vertical">
     <CheckBox>..</CheckBox>
     <Button>..</Button>
  </LinearLayout>

  <View   // this is what I want to achieve, dynamically
    android:layout_width="2dip"
    android:layout_height="fill_parent"
    android:background="#FAFFFB"/>

</TableRow>

1 个答案:

答案 0 :(得分:3)

试试这个:

View view = new View(this);
view.setLayoutParams(new LayoutParams(2,LayoutParams.FILL_PARENT));
view.setBackgroundColor(Color.BLACK);
layout.add(view);