开发者

How to animation Canvas that is drawn with code in Android?

I have code like this;

   AnimationSet s1 = new AnimationSet(true);
        TranslateAnimation tr1 = new TranslateAnimation(0, 0, -100, -200); 
        tr1.setDuration(6500);
        s1.addAnimation(tr1);
 开发者_如何学PythonPaint paint = new Paint();
    Bitmap b = Bitmap.createBitmap(90, 90, Bitmap.Config.ARGB_8888);
    Canvas c1 = new Canvas(b);
    c1.drawCircle(50, 100, 20, paint);

AnimationSet s2 = new AnimationSet(true);
        TranslateAnimation tr2 = new TranslateAnimation(0, 0, -140, -260); 
        tr2.setDuration(6500);
        s1.addAnimation(tr2);
    Canvas c2 = new Canvas(b);
    c2.drawCircle(150, 140, 20, paint);

How can I start animations s1 on canvas c1 and animation s2 on canvas c2? If I subsclass View class then I can call startAnimation method on the view class but how can I tie aboves canvases with above animations using View class? Sample code would be very helpful. I could not find a clean Android API that allows me to specify the target of animation. There should be an API that given a sequence of animations specify any target graphic object -- which in my case is the canvas object -- (not just the built-in graphic objects such as Button) on which the animation sequence is to be operated on.


You can add you Canvas as the Image of some component like a ImageView and then animate the view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜