2011-03-20 184 views
2

我想在表格行內動態繪製垂直線。有些東西就像下面的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> 

回答

3

試試這個:

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