将程序更改为动态壁纸

发布于 2024-12-09 03:47:21 字数 341 浏览 0 评论 0原文

我有一个图形程序,我想将其操作为 liveWallpaper。我浏览了几个教程,看起来它非常适合该模型。

所以我开始了,但很快我意识到 LiveWallpaper 并不像 SurfaceView 那样。

好吧..所以我明白了.. SurfaceHolder obj = getSurfaceHolder();然后是一些处理表面的方法..

有人介意给我快速概述..我对 onSurfaceChaanged()、OnVisibilityChanged、OnSurfaceCreated()、OnSurfaceDestroyed 没有很好的解释。似乎你得到了一个很好的动态壁纸布局,你可以使用一个非常通用的模板并把它们搞出来。

I have a graphical program that I would like to manipulate to liveWallpaper.. I went through a couple of the tutorials and it looked like it fit the mold pretty well.

So I started but soon I realized that LiveWallpaper doesn't SurfaceView.

fine.. so I see.. SurfaceHolder obj = getSurfaceHolder(); then some methods to deal w/ the surface..

anyone mind giving me the quick rundown.. I don't have good explanation for onSurfaceChaanged(), OnVisibilityChanged, OnSurfaceCreated(), OnSurfaceDestroyed. Seems like one you get a good layout for LiveWallpaper you can just use a pretty generic template and crank em out..

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

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

发布评论

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

评论(1

女皇必胜 2024-12-16 03:47:21

我使用以下代码来绘制壁纸:

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

    Canvas c = null;
    try {
        c = holder.lockCanvas();
        if (c != null) {
            //do your drawing here
        }
    } finally {
        if (c != null) holder.unlockCanvasAndPost(c);
    }
}

使用此代码,您可以按照习惯在画布上绘制。

我个人不会重写 onSurfaceChanged() 和 onSurfaceDestroyed()。我确实重写 onSurfaceCreated() 来开始绘图。如果 LWP 变得可见/不可见,您需要 onVisibilityChanged() 来启动/停止绘图。

I use the following code to paint the wallpaper:

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

    Canvas c = null;
    try {
        c = holder.lockCanvas();
        if (c != null) {
            //do your drawing here
        }
    } finally {
        if (c != null) holder.unlockCanvasAndPost(c);
    }
}

Using this you can draw on a Canvas as you are used to.

I personally don't override onSurfaceChanged() and onSurfaceDestroyed(). I do override onSurfaceCreated() to start drawing. You need onVisibilityChanged() to start/stop the drawing if the LWP becomes visible/invisible.

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