Android动态壁纸的制作教程.docx

上传人:汽*** 文档编号:556604371 上传时间:2023-01-27 格式:DOCX 页数:8 大小:39.51KB
返回 下载 相关 举报
Android动态壁纸的制作教程.docx_第1页
第1页 / 共8页
Android动态壁纸的制作教程.docx_第2页
第2页 / 共8页
Android动态壁纸的制作教程.docx_第3页
第3页 / 共8页
Android动态壁纸的制作教程.docx_第4页
第4页 / 共8页
Android动态壁纸的制作教程.docx_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《Android动态壁纸的制作教程.docx》由会员分享,可在线阅读,更多相关《Android动态壁纸的制作教程.docx(8页珍藏版)》请在金锄头文库上搜索。

1、动态壁纸是在Android 2.1新增的一个功能。动态壁纸可以添加到Android的桌面,具有交互式的动画背景效果。在本教程中,我们将教会你如何去制作一个交互式的动态壁纸。动态壁纸是一个Android应用程序,包括一个服务(WallpaperService)。该服务必须包括一个引擎(WallpaperService.Engine)。该引擎是连接用户、桌面、系统之间的桥梁。它也可以绘制桌面壁纸。首先,必须由内在的Engine类创建一个WallpaperService类。该服务必须在AndroidManifest.xml中声明为android.service.wallpaper.Wallpaper

2、Service,这样它才会作为动态壁纸被手机识别。而且还要在服务配置中附加android.permission.BIND_WALLPAPER的权限许可:?12345678910111213创建一个XML文件,放置在应用程序目录下的/res/xml/中。它用来描述你的动态壁纸。?123456再创建一个xml的属性文件attrs.xml,代码如下:?1234567891011121314动态壁纸的服务代码如下:?1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515

3、25354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105package net.androgames.blog.sample.livewallpaper;import android.content.SharedPreferences;import android.service.wallpaper.WallpaperService;import android.view.MotionEvent;import android.

4、view.SurfaceHolder;/* Android Live Wallpaper Archetype* author antoine vianey* under GPL v3 : http:/www.gnu.org/licenses/gpl-3.0.html*/public class LiveWallpaperService extends WallpaperService Overridepublic Engine onCreateEngine() return new SampleEngine();Overridepublic void onCreate() super.onCr

5、eate();Overridepublic void onDestroy() super.onDestroy();public class SampleEngine extends Engine private LiveWallpaperPainting painting;SampleEngine() SurfaceHolder holder = getSurfaceHolder();painting = new LiveWallpaperPainting(holder, getApplicationContext();Overridepublic void onCreate(SurfaceH

6、older surfaceHolder) super.onCreate(surfaceHolder);/ register listeners and callbacks heresetTouchEventsEnabled(true);Overridepublic void onDestroy() super.onDestroy();/ remove listeners and callbacks herepainting.stopPainting();Overridepublic void onVisibilityChanged(boolean visible) if (visible) /

7、 register listeners and callbacks herepainting.resumePainting(); else / remove listeners and callbacks herepainting.pausePainting();Overridepublic void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) super.onSurfaceChanged(holder, format, width, height);painting.setSurfaceS

8、ize(width, height);Overridepublic void onSurfaceCreated(SurfaceHolder holder) super.onSurfaceCreated(holder);/ start paintingpainting.start();Overridepublic void onSurfaceDestroyed(SurfaceHolder holder) super.onSurfaceDestroyed(holder);boolean retry = true;painting.stopPainting();while (retry) try painting.join();retry = false; c

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号