首页 > 学院 > 开发设计 > 正文

TextView添加边框

2019-11-06 09:45:40
字体:
来源:转载
供稿:网友
package com.chezi008.multiplypoplib.view;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.view.Gravity;import android.widget.TextView;/** * 描述:加速控件的子视图 * 作者:chezi008 on 2017/2/27 15:35 * 邮箱:chezi008@163.com */public class ItemMultiplyView extends TextView { PRivate int sroke_width =2; public ItemMultiplyView(Context context) { super(context); } public ItemMultiplyView(Context context, AttributeSet attrs) { super(context, attrs); } public ItemMultiplyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); // 将边框设为红色 paint.setColor(Color.RED); // 画TextView的4个边 //top canvas.drawLine(0, 0, this.getWidth() - sroke_width, 0, paint); //left canvas.drawLine(0, 0, 0, this.getHeight() - sroke_width, paint); //bomott canvas.drawLine(this.getWidth() - sroke_width, 0, this.getWidth() - sroke_width, this.getHeight() - sroke_width, paint); //right canvas.drawLine(0, this.getHeight() - sroke_width, this.getWidth() - sroke_width, this.getHeight() - sroke_width, paint); super.onDraw(canvas); }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表