How to draw horizontal and vertical line in Table layout

后端 未结 1 1952
情歌与酒
情歌与酒 2021-01-05 06:01

I want a vertical and horizontal line drawn inside the a table row.

i cant attach image

i tried drawing lines around TextView in table

相关标签:
1条回答
  • 2021-01-05 06:15

    For horizontal line

    view v = new View(this);
                v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 1));
    

    For Vertical line

     view v = new View(this);
     v.setLayoutParams(new TableRow.LayoutParams(1, TableRow.LayoutParams.MATCH_PARENT));
    

    add this in your code and add it to table row Programmatically

    Edited:

    TableRow row;
    row=(TableRow)findViewById(R.id.traningprogram_tableRow_mondayHeading);
    row.addView(v);
    

    if you want to create it in xml itself use this code after your each row items(TextView)

    for Horizontal line in XML

    <View android:layout_width="match_parent"
          android:background="@android:color/red" 
                        android:layout_height="2dp" />
    

    for vertical line in XML

    <View android:layout_width="2dp"
          android:background="@android:color/red" 
          android:layout_height="match_parent"/>
    

    Try this it will work

    0 讨论(0)
提交回复
热议问题