大家好,我想在画布上绘制简单的路径线条,应该会绘制出红色矩形和白色线条,但是它什么都没有绘制出来,我错过了什么吗? 下面是我的代码:
Canvas canvas = new Canvas();
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
canvas.drawPaint(paint);
Path path = new Path();
//canvas.drawColor(Color.CYAN);
for (int i = 5; i < 50; i++) {
path.moveTo(4, i-1);
path.lineTo(4, i);
}
path.close();
paint.setStrokeWidth(3);
paint.setPathEffect(null);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
canvas.drawPath(path, paint);
for (int i = 0; i < 3; i++) {
View iview = inflater.inflate(R.layout.linear_layout, null);
if(i == 0){
iview.findViewById(R.id.imageView1).setBackgroundResource(R.drawable.distspeed);
}
if(i == 1){
iview.findViewById(R.id.imageView1).setBackgroundResource(R.drawable.hxmdist);
}
if(i == 2){
iview.findViewById(R.id.imageView1).setBackgroundResource(R.drawable.hxmspeeed);
}
iview.draw(canvas);
realViewSwitcher.addView(iview);
}