【发布时间】:2012-04-17 19:59:27
【问题描述】:
我正在尝试做一个简单的绘画应用程序,但每次我调用 onDraw 时,它都会删除我之前的内容。在我的绘制中,我正在执行以下操作(其中点是具有 x 和 y 整数的类,“点”是列表点):
Paint paint = new Paint();
int c = getPaintFromActivityClass();
paint.setColor(c);
Path path = new Path();
boolean first = true;
for(Point point : points){
if(first){
first = false;
path.moveTo(point.x, point.y);
}
else{
path.lineTo(point.x, point.y);
}
}
canvas.drawPath(path, paint);
我每次都尝试将“旧”路径添加到新路径中,本质上是将路径彼此连接起来,并创建单独的(未连接的)路径。但是,在 onDraw 中,我还设置了另一个视图正在更改的油漆颜色。当我将路径相互添加时,更改颜色会改变所有路径的颜色。
【问题讨论】:
-
在位图上画路径,然后再画这个位图
-
@Selvin 我就是这么想的,但是如何在位图上绘制路径?
-
你在哪里使用
invalidate()?
标签: android android-view