我有一个Canvas。当用户点击显示时,我使用ShapeDrawable在画布上画一个红色的圆圈。我将每个圆圈加到List<ShapeDrawable>中,称为hits。但我只想让最后一个圆圈变成红色,所有其他的都重新染成蓝色。
这是我的代码:
if (e.Event.Action == MotionEventActions.Up)
{
int x = (int) e.Event.GetX();
int y = (int) e.Event.GetY();
ShapeDrawable s = new ShapeDrawable(new OvalShape());
s.Paint.Color = Color.Red;
s.SetIntrinsicWidth(30);
s.SetIntrinsicHeight(30);
double widthRatio = canvas.Width/(double) imageView.Width;
double heightRatio = canvas.Height/(double) imageView.Height;
s.SetBounds((int) (x*widthRatio - 15), (int) (y*heightRatio - 15), (int) (x*widthRatio + 15),
(int) (y*heightRatio + 15));
s.Draw(canvas);
foreach (var shapeDrawable in hits)
{
shapeDrawable.Paint.Color = Color.Blue;
shapeDrawable.InvalidateSelf();
}
hits.Add(s);
imageView.Invalidate();
}但颜色并没有改变。请问我做错什么了?
发布于 2016-02-11 10:38:46
如果有人在寻找同一个问题的答案,下面是我解决这个问题的方法。我认为不可能改变已经在Canvas上使用的东西。因此,我被迫创建一个从ImageView继承的自定义视图,该视图有一个位图作为背景,我保存了每个被触摸到List的点,并重写了onDraw(Canvas canvas),在这里,我使用特定的Paint重新绘制List中的每个点。
发布于 2016-02-02 17:21:51
代替你的台词
s.Paint.Color = Color.Red;
shapeDrawable.Paint.Color = Color.Blue;尝试以下几点:
s.FillStyle = FillStyle.Solid;
s.FillColor = Color.Red;希望这能有所帮助。
https://stackoverflow.com/questions/35159531
复制相似问题