Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw horizontal and vertical line in Table layout

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 row but lines are not connecting properly below is my xml and style

 <TableLayout
    android:id="@+id/traningprogram_tabla_monday"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="0,1,2,3"
     >

            <TableRow
                android:id="@+id/traningprogram_tableRow_mondayHeading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 

                >

                <TextView
                    android:id="@+id/traningprogram_textView_mondayheadingWeek"
                    android:layout_width="0dip"
                      android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:padding="5dp"
                    android:textSize="12dp"
                    android:text="TextView" />

                <TextView
                    android:id="@+id/traningprogram_textView_mondeyheadingWeekName"
                    android:layout_width="0dp"
                    android:layout_height="25dp"
                    android:layout_weight="1"
                    android:padding="5dp"
                    android:textSize="12dp"
                    android:text="TextView" />

            </TableRow>


            <TableRow android:id="@+id/traningprogram_tableRow_workspeed" android:layout_width="wrap_content" android:layout_height="wrap_content">                    


                <TextView
                    android:id="@+id/traningprogram_textView_workspeed"
                    android:layout_width="0dip"
                     android:layout_weight="1"
                    android:layout_height="25dp"
                    android:background="@drawable/cell_shape"
                    android:padding="5dp"
                    android:text="@string/workspeed"
                    android:textSize="12dp"

                    ></TextView>

               <TextView 
                   android:background="@drawable/cell_shape" 
                   android:padding="5dp" 
                   android:id="@+id/traningprogram_textView_workspeedvalue"
                   android:layout_width="0dip" 
                   android:layout_weight="1" 
                   android:layout_height="25dp"  
                   android:textSize="12dp"
                   android:text="TextView"></TextView>

            </TableRow>


               <TableRow android:id="@+id/traningprogram_tableRow_recoveryspeed" android:layout_width="match_parent" android:layout_height="wrap_content">                    


                <TextView
                    android:id="@+id/traningprogram__textView_recoveryspeed"
                    android:layout_width="0dip"
                    android:layout_height="25dp"
                    android:layout_weight="1"
                    android:background="@drawable/cell_shape"
                    android:padding="5dp"
                     android:textSize="12dp"
                    android:text="@string/recoveryspeed" ></TextView>

                <TextView 
                    android:background="@drawable/cell_shape" 
                    android:padding="5dp" 
                    android:layout_weight="1"
                    android:textSize="12dp"
                    android:id="@+id/traningprogram_textView_recoverspeedvalue" 
                    android:layout_width="0dp" android:layout_height="25dp"  
                    android:text="TextView"></TextView>

            </TableRow>
            <TableRow android:id="@+id/traningprogram_tableRow_workduration" android:layout_width="match_parent" android:layout_height="wrap_content">                    


                <TextView
                    android:id="@+id/traningprogram_textView_workduration"
                    android:layout_width="0dip"
                    android:layout_height="25dp"
                    android:layout_weight="1"
                    android:background="@drawable/cell_shape"
                    android:padding="5dp"
                    android:textSize="12dp"
                    android:text="@string/workduration" ></TextView>

                <TextView 
                    android:background="@drawable/cell_shape" 
                    android:padding="5dp" 
                    android:layout_weight="1"
                     android:textSize="12dp"
                    android:id="@+id/textView_workdurationValue" 
                    android:layout_width="0dp" 
                    android:layout_height="25dp"  
                    android:text="TextView"></TextView>

            </TableRow>

             <TableRow android:id="@+id/traningprogram_tableRow_recoverduration" android:layout_width="match_parent" android:layout_height="wrap_content">                    


                <TextView
                    android:id="@+id/traningprogram_textViewrecoverduration"
                    android:layout_width="0dip"
                    android:layout_height="25dp"
                    android:layout_weight="1"
                    android:background="@drawable/cell_shape"
                    android:padding="3dp"
                    android:text="@string/recoveryduration" ></TextView>

                <TextView
                    android:id="@+id/traningprogram_textView_recoverydurationvalue"
                    android:layout_width="0dip"
                    android:layout_height="25dp"
                    android:layout_weight="1"
                    android:padding="3dp"
                    android:text="TextView"
                    android:textSize="12dp" />

            </TableRow>

              <TableRow android:id="@+id/traningprogram__tableRow_repe" android:layout_width="match_parent" android:layout_height="wrap_content">                    


                <TextView
                    android:id="@+id/traningprogram_textView_repes"
                    android:layout_width="0dip"
                    android:layout_height="25dp"
                    android:layout_weight="1"
                    android:background="@drawable/cell_shape"
                    android:padding="5dp"
                     android:textSize="12dp"
                    android:text="@string/reps" >
                  </TextView>
                <TextView 
                    android:background="@drawable/cell_shape" 
                    android:padding="5dp" 
                    android:id="@+id/traningprogram_textView_repes"
                     android:layout_width="0dip"
                     android:layout_weight="1" 
                     android:layout_height="25dp"  
                      android:textSize="12dp"
                     android:text="TextView"></TextView>

            </TableRow>
        </TableLayout>

drawable/cell_shape

  <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:bottom="1dp"
        android:left="-2dp"
        android:right="1dp"
        android:top="-3dp">
        <shape android:shape="rectangle" >
            <stroke
                android:width="1dp"
                android:color="#FF000000" />

            <solid android:color="#00FFFFFF" />
        </shape>
    </item>

</layer-list>

Thanks in advance for help

like image 676
user1737884 Avatar asked Nov 02 '12 05:11

user1737884


1 Answers

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

like image 173
Zombie Avatar answered Nov 26 '22 00:11

Zombie