使用canvas画布和paint画笔可以自定义view
案例:fastindexbar
基本用法
public class DrawView extends View{ private Rect mRect; private Paint paint; public DrawView(Context context) { super(context); //参数:左,上,右,下 // left 矩形左上角X坐标值 // top 矩形左上角Y坐标值 // right 矩形右下角X坐标值 // bottom 矩形右下角Y坐标值 mRect = new Rect(100,100,200,200); paint = new Paint(); paint.setColor(Color.BLUE); paint.setStrokeWidth(3); } //画笔 @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawRect(mRect, paint);
//重绘 invalidate(); } }