我是Android画布绘图的新手,我需要在android Canvas上绘制随机的发光点,该点会定期进行动画处理(例如淡出并重新出现)。经过几次尝试,我尝试了下面的代码;
private void preparePoints(){
if(circles.size()>0) circles.clear();
for(int i=0;i<width/10;i++)
circles.add(new Circle(width,height));
}
private void drawPoints(Canvas canvas){
List<Circle> dumpCircles = circles;
preparePoints();
for(int i = 0; i< dumpCircles.size(); i++) {
Circle point = dumpCircles.get(i);
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setAntiAlias(true);
mPaint.setShader(new RadialGradient(point.getX(),point.getY()-(indexCount*5),point.getR()+5,
new int[] { Color.argb((200-clamp(indexCount*5,0,200)),192,255,250),Color.argb(180-clamp(indexCount*5,0,180),99,164,184),
Color.argb(128-clamp(indexCount*5,0,128),5,74,119),Color.argb(96-clamp(indexCount*5,0,96),0,40,80)},
new float[] { 0.0f, 0.26f, 0.62f,0f } , Shader.TileMode.CLAMP));
if(canvas!=null) {
canvas.drawCircle(point.getX(), point.getY()-(indexCount*5), point.getR(), mPaint);
}
else break;
}
}
public static int clamp(float val, float min, float max) {
return (int)Math.max(min, Math.min(max, val));
}
“圆形”是自定义类,可生成点的随机坐标和半径。
但是看起来它在画布上造成了很多滞后,并且没有按正确的顺序生成点。
如果有人可以建议我以最佳方式在画布Something like this上绘制发光的动画点,我将感到非常满足。
提前一吨。!