Android 动态壁纸问题

发布于 2024-10-06 23:34:34 字数 681 浏览 7 评论 0原文

我今天一直在摆弄动态壁纸,你知道吗,我就是无法让它工作。

我决定提出尽可能最简单的动态壁纸并从那里开始构建,但即使这样也出了问题!这就是我的壁纸服务类的组成,

    @Override
    public Engine onCreateEngine() {
 return new SimpleEngine();
    }
    public class SimpleEngine extends Engine {

        @Override
        public void onSurfaceCreated(SurfaceHolder holder) {
            super.onSurfaceCreated(holder);

            Canvas c = holder.lockCanvas();
            Paint paint = new Paint();
            paint.setColor(Color.BLUE);
            c.drawCircle(50, 50, 50, paint);
        }
    }

我想要测试的是是否可以在屏幕上出现一个小圆圈,但是当我将其设置为我的壁纸时,它只是说“正在加载动态壁纸...”并且没有不让步(但它也不会冻结)。代码正在被调用,但我不确定出了什么问题。

有人可以帮我指出吗?

I'v been tinkering with Live Wallpapers today and wouldn't you know it, I just can't get it to work.

I decided to come up with the most simple live wallpaper possible and build from there but even that is going wrong! This is what my WallpaperService class consists of,

    @Override
    public Engine onCreateEngine() {
 return new SimpleEngine();
    }
    public class SimpleEngine extends Engine {

        @Override
        public void onSurfaceCreated(SurfaceHolder holder) {
            super.onSurfaceCreated(holder);

            Canvas c = holder.lockCanvas();
            Paint paint = new Paint();
            paint.setColor(Color.BLUE);
            c.drawCircle(50, 50, 50, paint);
        }
    }

All I wanted to test was if I could make a little circle appear on the screen, but when I go to set it as my wallpaper it just says "Loading live wallpaper..." and doesn't budge (but it doesn't freeze either). The code is getting called but I'm not sure whats going wrong.

Could someone point it out for me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分分钟 2024-10-13 23:34:34

我猜你最后缺少 SurfaceHolder.unlockCanvasAndPost

I guess you are missing SurfaceHolder.unlockCanvasAndPost at the end

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文