繁体   English   中英

安卓动态壁纸的图像?

[英]android live wallpaper with image?

->我已经创建了一个应用程序。

->在应用程序中,我拍摄了10张图片。

->我的问题是,我已将10张图像中的一张设置为动态壁纸,但是一段时间后它没有移动,我的代码如下:

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Canvas;

import android.service.wallpaper.WallpaperService;

import android.view.SurfaceHolder;



public class LiveWallpaperService extends WallpaperService 
{
    public void onCreate() 

    {
        super.onCreate();
    }

    public void onDestroy() 
    {
        super.onDestroy();
    }

    public Engine onCreateEngine() 
    {
        return new WallpaperSerEngine();
    }

    class WallpaperSerEngine extends Engine 
    {
        public Bitmap image1; 
        public Bitmap image2;
        public Bitmap image3;

        WallpaperSerEngine() 
        {       
                image1 = BitmapFactory.decodeResource(getResources(), R.drawable.fish);
                image2 = BitmapFactory.decodeResource(getResources(), R.drawable.fish1);       
                image3 = BitmapFactory.decodeResource(getResources(), R.drawable.fish2); 

        }

        public void onCreate(SurfaceHolder surfaceHolder) 
        {
            super.onCreate(surfaceHolder);
        }

        public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels) 
        {
            drawFrame();

        }

        void drawFrame() 
        {
            final SurfaceHolder holder = getSurfaceHolder();

            Canvas c = null;
            try 
            {
                c = holder.lockCanvas();
                if (c != null) 
                {              
                     c.drawBitmap(image1, 0, 0, null);
                     c.drawBitmap(image2, 0, 0, null);
                     c.drawBitmap(image3, 0, 0, null);

                }
            } finally 
            {
                if (c != null) holder.unlockCanvasAndPost(c);
            }
        }
    }
}

您的代码没有任何意义。 仅当用户滚动墙纸时,您才绘制框架。 所有位图都放置在点(0,0),其位置将保持不变。

我对您的建议是尝试使用此动态壁纸模板

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM