Question

I'm trying to add different animations using matrix.setRotate (45), etc. to the Live Wallpaper, but it didn't work. All it did was showing the pictures in 45 degrees. I thought it would be rotating to 45 degrees?

I would like to add different animations to the slideshow live wallpaper like rotation, fading, translation, transformation, scaling, etc.

I even tried

matrix.setRotate(90);

matrix.setTranslate(100, 100);

but the pictures showed up very weird. Perhaps, there was any animation....

I know how to apply the animations from res/anim/animation.xml to NONE live wallpaper, but I can't seem to find a way to apply this animation.xml to the Live Wallpaper.

Is possible and easy way to apply animations to Live Wallpaper?

Thank you very much for your help in advance.

Java Code:

......

.....

....

private void drawFrame() {
    // TODO Auto-generated method stub
    final SurfaceHolder holder = getSurfaceHolder();
    Canvas c = null;
    try {
        c = holder.lockCanvas();
        if (c != null) {


            drawPirate(c);
        }
    } finally {
        if (c != null)
            holder.unlockCanvasAndPost(c);
    }
    mhandler.removeCallbacks(drawrunnable);
        if (mVisible) {
            mhandler.postDelayed(drawrunnable);
        }
    }

private void drawPirate(Canvas c) {
    // TODO Auto-generated method stub

    Bitmap icon;              
    Matrix matrix = new Matrix();
    matrix.setRotate(45);

    icon = BitmapFactory.decodeResource(getResources(),pirates[i]);
    c.drawBitmap(icon, matrix, null);
    icon.recycle();
 }

}

Was it helpful?

Solution

I'm not familiar with live wallpapers, but hopefully I can answer some of your other questions.

  1. setRotate is not an animator, it rotates to its setting all at once
  2. Good way to do this would be to create a thread for your drawFrame() and have it loop calling drawPirate(c), while incrementing the rotation value each time, so that you draw your image at setRotate(1), setRotate(2), etc until 45. You might want to look at the JetBoy android sample code for this kind of an implementation.
  3. It is not good practice to allocate new things and decodeResources in the draw method. When you make multiple calls to it, it will have to create the new things every time and will slow things down a lot.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top