通过自定义一个类,继承TextView,给TextView加上边框的效果:
package com.focus.fishme;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.widget.TextView;
public class FishMeTextView extends TextView {
public FishMeTextView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Paint paint = new Paint();
// 将边框设为黑色.
paint.setColor(android.graphics.Color.RED);
// 画TextView的4个边.
canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint);
canvas.drawLine(0, 0, 0, this.getHeight() - 1, paint);
canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1, this.getHeight() - 1, paint);
canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1, this.getHeight() - 1, paint);
}
}
652

被折叠的 条评论
为什么被折叠?



