我想在这样的表格中间画一条水平线
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<solid android:color="#ffffff" />
<stroke android:width="2dip"
android:color="#FF0000" android:dashWidth="2dp"/>
</shape>
但是用java代码
由于您没有为表格行添加 java 代码,我将做假设:
假设您拥有的代码位于 Drawable 文件夹内命名的 xml 文件中line.xml,假设我们有TableRow myRow = new TableRow(this);
现在我们将line.xml在 Java 代码中转换为 Drawable,
Resources res = getResources();
Drawable line = res.getDrawable(R.drawable.line);
现在您只需将其添加到视图中以将其放在表格行的中间,例如:
TextView tv = new TextView(this);
tv.setBackground(line);
然后将其添加到您的表格行中,
myRow.addView(tv);
我没试过,但你可以试一试,祝你好运