如何画水平和垂直线表布局垂直线、布局、水平和

2023-09-06 13:52:50 作者:2.故事与酒

我要的垂直和水平线的该表行内绘制。

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

我不能附加图片

我想周围绘制的TextView 行的表行,但行未正确连接  下面是我的 XML 和风格

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>

绘制/ 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

推荐答案

对于水平线

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

垂直线

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

在你的code加上这一点,并把它添加到编程表行

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

编辑:

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

如果你想在创建它的 XML 本身的每一行项目后使用code(的TextView

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

的Hotizontal行XML

<View android:layout_width="match_parent"
                    android:layout_height="2dp" />

在XML垂直线

<View android:layout_width="2dp"
              android:layout_height="match_parent"/>

试试这个它会工作

Try this it will work