private void init() {
mLinePaint = new Paint();
mLinePaint.setStyle(Paint.Style.STROKE);
mLinePaint.setStrokeWidth(GRID_LINE_WIDTH);
mLinePaint.setAntiAlias(true);//抗锯齿效果
mWavePaint = new Paint();
mWavePaint.setStyle(Paint.Style.STROKE);
mWavePaint.setColor(mWaveLineColor);
mWavePaint.setStrokeWidth(WAVE_LINE_STROKE_WIDTH);
mWavePaint.setAntiAlias(true);//抗锯齿效果
mPath = new Path();
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
mWidth = getMeasuredWidth();//获取view的宽
mHeight = getMeasuredHeight();//获取view的高
row= (int) (mWidth/(GRID_SMALL_WIDTH));//获取行数
//小网格
xSmallNum = (int) (mHeight/GRID_SMALL_WIDTH);//横线个数=总高度/小网格高度
ySmallNum = (int) (mWidth/GRID_SMALL_WIDTH);//竖线个数=总宽度/小网格宽度
//大网格
xBigNum = (int) (mHeight/GRID_BIG_WIDTH);//横线个数
yBigNum = (int) (mWidth/GRID_BIG_WIDTH);//竖线个数
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//绘制网格
drawGrid(canvas);
//绘制波形
drawWaveLine(canvas);
}
/**
* 画折线
* @param canvas
*/
private void drawWaveLine(Canvas canvas) {
if(null =&#
Android自定义View——心电图,曲线图,波形图
于 2024-04-30 12:45:21 首次发布