如何绘制表格布局中的水平和垂直线
问题描述:
我想要一个垂直和水平线绘制在表格行内。如何绘制表格布局中的水平和垂直线
我不能附加图片
我试图绘制在表行围绕TextView
线,但线不正确下面连接 是我XML和风格
<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>
个
预先感谢帮助
答
对于水平线
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));
在代码中添加这一点,并把它添加到表行编程
编辑:
TableRow row;
row=(TableRow)findViewById(R.id.traningprogram_tableRow_mondayHeading);
row.addView(v);
如果你想在
XML创建它本身在XML
<View android:layout_width="match_parent"
android:background="@android:color/red"
android:layout_height="2dp" />
使用此代码的每一行项目(
TextView
)
为水平线后
XML中的垂直线
<View android:layout_width="2dp"
android:background="@android:color/red"
android:layout_height="match_parent"/>
试试这个它会工作
它不工作 – user1737884
现在我编辑的代码尝试...您展示如何使用代码,即使这不工作 – Zombie
它没有显示在表行中的任何行'的TableRow行=(的TableRow)findViewById (R.id.traningprogram_tableRow_mondayHeading); 查看v = new View(this); v.setBackgroundColor(android.R.color.darker_gray); v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,2)); 查看v2 = new View(this); v2.setBackgroundColor(android.R.color.darker_gray); v2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,2)); row.addView(v); 行。addView(v2);' – user1737884