【发布时间】:2016-02-02 17:04:42
【问题描述】:
我有一个Canvas。当用户点击显示屏时,我使用ShapeDrawable 在画布上绘制了一个红色圆圈。我将每个圈子添加到 List<ShapeDrawable> 称为点击。但我只想将最后一个圆圈变为红色,将所有其他圆圈重新着色为蓝色。
这是我的代码:
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();
}
但颜色没有变化。请问我做错了什么?
【问题讨论】:
标签: c# android canvas xamarin shape