我想在桌台中间画一条水平线
<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文件夹内名为line.xml
的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);
我没有尝试过,但是您可以试一试,祝您好运
关于android - 以编程方式在 table 上画线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10821833/