setUnderlineText(booleanunderlineText) // 设置下划线
Canvas类常用方法:
mCanvas.drawARGB(122, 10, 159, 163) ;// 1、将会以颜色ARBG填充整个控件的Canvas背景
mCanvas.drawColor(Color.BLUE) ;// 2、将会以颜色ARBG填充整个控件的Canvas背景
mCanvas.drawColor(Color.BLUE, Mode.SCREEN) ;// 3、绘制颜色,但是要制定一个mode
mCanvas.drawPaint(mPaint) ;// 4、画背景,跟2等效
mCanvas.drawPoint(23, 23, mPaint) ;// 5、画一个点
mCanvas.drawPoints(new float[]{10,11,10,12,10,13,10,14,10,15,10,16}, mPaint) ;// 6、画很多点这里的float[] 表示{x0,y0,x1,y1,x2,y2,x3,y3.....}
mCanvas.drawLine(...) ;// 7、画线
// 8、画长方形 Rect 和RectF的区别?
//精度不一样,Rect是使用int类型作为数值,RectF是使用float类型作为数值
Rect r = new Rect(10,10,50,50) ;
mCanvas.drawRect(r, mPaint) ;
RectF rf = new RectF(10,10,50,50) ;
mCanvas.drawRect(rf, mPaint) ;
mCanvas.drawRect(10, 10, 50, 50, mPaint) ;
// 9、画椭圆 初始化RectF的参数是(left,top,right,bottom)
RectF rf = new RectF(100,100 ,200 ,250) ;
mCanvas.drawOval(rf, mPaint) ;
// 10、画圆 (圆心x0,圆心y0,半径,paint)
mCanvas.drawCircle(100, 100, 50, mPaint) ;
// 11、画圆弧 RectF对象表明内切矩形的(left,top,right,bottom)
//left:表示矩形左边距Y轴距离
//top:表示矩形上边距X轴距离
//right:表示矩形右边距Y轴距离
//bottom:表示矩形下边距X轴距离
RectF rf = new RectF(100 ,100 ,200 ,200) ;
// 参数(rf,startAngle ,angle ,sweepAngle ,paint) sweepAngle表明是否显示圆弧三角形 angle画多少度
mCanvas.drawArc(rf, 60, 30, true, mPaint) ;
// 12、绘制圆角矩形 RectF是矩形的(left,top,right,bottom);50表明x方向的半径,20表示y方向的半径
RectF rf = new RectF(100 ,100 ,200 ,200) ;
mCanvas.drawRoundRect(rf, 50, 20, mPaint) ;
// 13、画任意多边形
Path path = new Path() ;
path.moveTo(100, 100) ;
path.lineTo(200, 200) ;
path.lineTo(300, 200) ;
mCanvas.drawPath(path, mPaint) ;
// 14、通过Path对象,也可以画其他的图形
Path path = new Path() ;
path.addCircle(100, 100, 20, Path.Direction.CCW) ;
mCanvas.drawPath(path ,mPaint);
/*drawBitmap
drawText
drawPicture*/
/*Rect r = new Rect(100,100,200,200) ;
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.bg) ;
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out) ;
InputStream in = new ByteArrayInputStream(out.toByteArray()) ;
*/
/*Picture picture = Picture.createFromStream(mContext.getResources().openRawResource(R.raw.bg)) ;
mCanvas.drawPicture(picture) ;*/
// 15、画bitmap对象
mCanvas.drawBitmap(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.bg),100, 100, mPaint) ;
// 16、Matrix中包含了对Bitmap的处理操作
Matrix m = new Matrix() ;
m.postScale(2, 2) ;
m.postRotate(60) ;
mCanvas.drawBitmap(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.bg), m, mPaint) ;
// 17、画带Matrix参数的bitmap,经过Matrix对象可以对bitmap做相关的处理,比如旋转,缩放,移动等《关于Matrix的使用另行总结》
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.bg) ;
Matrix m = new Matrix() ;
m.postScale(2, 2) ;
m.postRotate(60) ;
m.postTranslate(300, 300) ;
mCanvas.drawBitmap(bitmap, m, mPaint) ;
// 18、画文字
mCanvas.drawText(123, 10, 10, mPaint) ;
// 19、旋转,(旋转角度,旋转中心x坐标,中心y坐标)
mCanvas.rotate(float,float,float);
// 20、save当前这个canvas的状态
mCanvas.save();
// 21、取出最近一次save的canvas的状态,
mCanvas.restore();