Android:在一个时间周期内在画布上绘制圆圈

时间:2014-02-03 17:04:23

标签: android animation canvas draw

我希望每秒在画布上绘制圆圈,每秒增加/减少直径,以创建“闪烁”效果。我试图使用runnable,但可能我错了,因为没有任何反应......也许有经验的人可以提供帮助,或者给我另一个想法来创建这种类型的效果......非常感谢

  public void drawLocation(Canvas c, Float posx, Float posy){  
    paint = new Paint(); 
    paint.setAntiAlias(true); 
    paint.setColor(Color.RED); 
    paint.setStyle(Paint.Style.STROKE);

    final Canvas canvas =c;
    final float px = posx;
    final float py = posy;

    final Handler handler = new Handler();

    for (int i = 1; i < 10;i++) {
        Log.i("drawLocation", "i = " + i);
        final int p = i;
        final Runnable r=new Runnable()
            {
            public void run() 
                {
                    canvas.drawCircle(px,py, p*scale, paint);
                    handler.postDelayed(this, 1000);
                    Log.i("drawLocation", "Delay 1000 ms ");
                }
            };
            handler.postDelayed(r, 1000);
    }

}

0 个答案:

没有答案