我正在尝试使用帧动画(来自资源的其他图像)创建 android 动态壁纸,代码看起来不错,但问题是壁纸没有显示(加载中的堆栈并且没有任何反应),这是我的代码:
public class lwpService extends WallpaperService {
int incrementer=0;
Bitmap bmps[]=new Bitmap[10];
public void onCreate()
{
super.onCreate();
}
public void onDestroy()
{
super.onDestroy();}
public Engine onCreateEngine()
{
return new WallpaperSerEngine();
}
ande 这里是引擎类。...
class WallpaperSerEngine extends Engine
{
int res[]={R.drawable.img_00,R.drawable.img_01};
WallpaperSerEngine()
{
for(int i=0;i<2;i++)
{
bmps[i]= BitmapFactory.decodeResource(getResources(),res[i]);
}
}
}
private final Handler handler = new Handler();
private final Runnable drawRunner = new Runnable() {
@Override
public void run() {
drawFrame();
}
};
void drawFrame()
{
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try
{
c = holder.lockCanvas();
if (c != null)
{
c.drawBitmap(bmps[incrementer], 0, 0, null);
incrementer=(incrementer==2)?0 : incrementer+1;
}
} finally
{
if (c != null) holder.unlockCanvasAndPost(c);
}
handler.removeCallbacks(drawRunner);
handler.postDelayed(drawRunner, 200);
}
private SurfaceHolder getSurfaceHolder() {
// TODO Auto-generated method stub
return null;
}
}
任何人都可以帮助我吗?谢谢 。