Reputation: 2158
I want to have a line between each row in TextView
.
Can original TextView
do this?
If not, how can I do it?
ANSWER:
Thanks to @Slartibartfast reference and advice. I made a customized TextView
. And I get something like this.
This is what I want!
The code:
public class LinedTextView extends TextView {
private Rect mRect;
private Paint mPaint;
public LinedTextView(Context context) {
super(context);
initialize();
}
public LinedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}
public LinedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initialize();
}
private void initialize() {
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(0x800000ff);
}
@Override
protected void onDraw(Canvas canvas) {
int cnt = getLineCount();
Rect r = mRect;
Paint paint = mPaint;
for (int i = 0; i < cnt; i++) {
int baseLine = getLineBounds(i, r);
canvas.drawLine(r.left, baseLine + 1, r.right, baseLine + 1, paint);
}
super.onDraw(canvas);
}
}
Upvotes: 4
Views: 1318
Reputation: 1526
Use the following line of code below your TextView
<View android:layout_width="fill_parent"
android:layout_height="1px"
android:background="@android:color/background_dark" />
You can configure it according to your need.
You can also use ListView
with divider.
Upvotes: 3