문제

I want to draw a horizontal line in middle of a tablerow like this

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

but with java code

도움이 되었습니까?

해결책

Since you didn't added the java code for your table row, I'll do assumptions:

Assume the code you have is in the xml file named line.xml inside Drawable folder, Assume we have TableRow myRow = new TableRow(this);

Now we will convert line.xml to a Drawable in Java code,

Resources res = getResources();
Drawable line = res.getDrawable(R.drawable.line);

Now you just have to add it inside a view to put it in middle of your table row, for example:

TextView tv = new TextView(this);
tv.setBackground(line);

Then add it inside your table row,

myRow.addView(tv);

I didn't try it but you can give it a shot, Good luck

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top