How to draw a horizontal and vertical line in a table layout

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

I can not attach the image

I tried to draw the lines around the TextView in the table row, but the rows are not connecting properly below 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> 

hoods / 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> 

Thank you in advance for your help.

+4
source share
2 answers

For the horizontal line

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

For the vertical line

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

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

Edited by:

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

if you want to create it in xml use this code after each element of the line ( TextView )

for horizontal line in XML

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

for vertical string in XML

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

Try it, it will work

+17
source

try this example. this code will show the creation of the border and show your data in different rows and columns.

How to create a table with borders in Android?

0
source

Source: https://habr.com/ru/post/1443586/


All Articles