0
i ont une source qui est une application de fond d'écran exemple, je veux importer un xml d'animationcomment importer des animations personnalisées xml dans une application de fond d'écran?
public WallpaperEngine(Resources r) {
image01=BitmapFactory.decodeResource(r,R.drawable.fire01);
image02=BitmapFactory.decodeResource(r,R.drawable.fire02);
bg=BitmapFactory.decodeResource(r,R.drawable.hktv);
px=1;
translateAnimation = AnimationUtils.loadAnimation(this, android.R.anim.translate_animation);
}
mais il y a une erreur à la ligne translate_animation
cannot find symbol variable translate_animation
Comment puis-je résoudre ce problème?
------ ------ update
package com.example.android.livewallpaper;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.service.wallpaper.WallpaperService;
import android.view.SurfaceHolder;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class FireLiveWallpaper extends WallpaperService {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public Engine onCreateEngine() {
return new WallpaperEngine(getResources());
}
public class WallpaperEngine extends Engine {
private final Handler handler=new Handler();
private Bitmap image; //Image
private Bitmap image01; //Image01 for fire01.PNG
private Bitmap image02; //Image02 for fire02.PNG
private Bitmap bg;
private Paint paint = new Paint();
private int px=0; //Flag for switch
private boolean visible;
private int width;
private int height;
private int _xOffset = 0;
private int _yOffset = 0;
final Animation translateAnimation;
private final Runnable drawThread=new Runnable() {
public void run() {
drawFrame();
}
};
public WallpaperEngine(Resources r) {
image01=BitmapFactory.decodeResource(r,R.drawable.fire01);
image02=BitmapFactory.decodeResource(r,R.drawable.fire02);
bg=BitmapFactory.decodeResource(r,R.drawable.hktv);
px=1;
translateAnimation = AnimationUtils.loadAnimation(this,R.anim.translate_animation);
}
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
}
@Override
public void onDestroy() {
super.onDestroy();
handler.removeCallbacks(drawThread);
}
@Override
public void onSurfaceChanged(SurfaceHolder holder,
int format,int width,int height) {
super.onSurfaceChanged(holder,format,width,height);
this.width =width;
this.height=height;
drawFrame();
}
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
visible=false;
handler.removeCallbacks(drawThread);
}
@Override
public void onVisibilityChanged(boolean visible) {
this.visible=visible;
if (visible) {
drawFrame();
} else {
handler.removeCallbacks(drawThread);
}
}
@Override
public void onOffsetsChanged(float xOffset,float yOffset,
float xStep,float yStep,int xPixels,int yPixels) {
_xOffset = xPixels;
_yOffset = yPixels;
drawFrame();
}
private void drawFrame() {
SurfaceHolder holder=getSurfaceHolder();
Canvas c=holder.lockCanvas();
c.drawBitmap(bg, _xOffset, _yOffset, paint);
//c.drawColor(Color.BLUE);
if (px == 1) {
image=image01;
px=2;
} else {
image=image02;
px=1 ;
}
c.drawBitmap(image, (width-image.getWidth())/2, (height-image.getHeight())/2, null);
holder.unlockCanvasAndPost(c);
handler.removeCallbacks(drawThread);
if (visible) handler.postDelayed(drawThread,100);
}
}
}
Après android enlevé. : impossible de trouver la variable de symbole anim – hkguile
@hkguile: assurez-vous d'avoir placé le fichier 'translate_animation.xml' dans le dossier' res/anim/'. si le dossier 'anim' n'existe pas alors créez-le dans le dossier' res' –
le fichier est déjà placé là – hkguile