80,351
社区成员
发帖
与我相关
我的任务
分享
public class BorderTextView extends TextView {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
// 将边框设为黑色
paint.setColor(android.graphics.Color.BLACK);
// 画TextView的4个边
canvas.drawLine(0, 0, this.getWidth(), 0, paint);//上
canvas.drawLine(0, 0, 0, this.getHeight(), paint);//左
canvas.drawLine(this.getWidth() - 1, 0, this.getWidth(), this.getHeight(), paint);//右
canvas.drawLine(0, this.getHeight() - 1, this.getWidth(), this.getHeight(), paint);//下
}
public BorderTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setLayoutParams(LayoutParams params) {
if(Tab.display.getWidth() == 480) {
params.width = (Tab.display.getWidth() - 32) / 4;
params.height = 40;
} else if(Tab.display.getWidth() == 240){
params.width = (Tab.display.getWidth() - 16) / 4;
params.height = 20;
} else if(Tab.display.getWidth() == 640) {
params.width = (Tab.display.getWidth() - 40) / 4;
params.height = 45;
} else if(Tab.display.getWidth() == 320) {
params.width = (Tab.display.getWidth() - 20) / 4;
params.height = 30;
} else {
params.width = (Tab.display.getWidth() - 32) / 4;
params.height = 40;
}
super.setLayoutParams(params);
}
}