问 题
when we scroll, the foreground of the home screen (icons, widgets, etc.) moves to the left or right by the full screen width, but the background image (or live wallpaper) only moves by a fraction of that width. My question is how get this effect. till now have done this.
SurfaceHolder holder = getSurfaceHolder(); Canvas canvas = null; try { canvas = holder.lockCanvas(); if (canvas != null) { drawCircles(canvas); } } finally { if (canvas != null) holder.unlockCanvasAndPost(canvas); }the draw function is
{ private void draw(Canvas canvas) { Paint paint = new Paint(); DisplayMetrics metdisplayMatrics = new DisplayMetrics(); Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); display.getMetrics(metdisplayMatrics); canvas.save(); canvas.drawColor(0xff000000); mRecscreenRectangleFrame = new Rect(0, 0, (int) (metdisplayMatrics.widthPixels*2.0), metdisplayMatrics.heightPixels); photo1= BitmapFactory.decodeResource(getResources(), R.drawable.img1); canvas.drawBitmap(photo1, null,mRecscreenRectangleFrame, paint); photo1.recycle(); System.gc(); }Now how to put live wallpapers parallax-scrolling effect.
@Override public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) { super.onOffsetsChanged(xOffset, yOffset, xOffsetStep, yOffsetStep, xPixelOffset, yPixelOffset); WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext()); View view=new View(getBaseContext()); myWallpaperManager.setWallpaperOffsets(view.getWindowToken(),xOffset, 0f); }Not working yet.................
解决方案
Call WallpaperManager.setWallpaperOffsets to instruct the wallpaper to scroll.
So this should center the wallpaper:
WallpaperManager.setWallpaperOffsets(getWindowToken(), 0.5f, 0f);This should scroll it to the side:
WallpaperManager.setWallpaperOffsets(getWindowToken(), 0f, 0f);This should scroll it to the other side:
WallpaperManager.setWallpaperOffsets(getWindowToken(), 1f, 0f);If you're going to do this, you ought to ensure that you know that the wallpaper can actually be scrolled, or that the user has asked you to enable scrolling. Many devices are configured with wallpaper that is the same size as the screen and does not scroll.
本文地址:IT屋 » android live wallpapers parallax-scrolling effect
问 题
当我们滚动,主屏幕的前景(图标,窗口小部件等),移动到左边或右边的全屏幕宽度,但背景图像(或动态壁纸)仅移动由宽的一小部分。 我的问题是如何让这种效果。 到现在已经做到了这一点。
SurfaceHolder持有人= getSurfaceHolder(); 帆布油画= NULL; 尝试 { 画布= holder.lockCanvas(); 如果(帆布!= NULL){ drawCircles(画布); } } 最后 { 如果(帆布!= NULL) holder.unlockCanvasAndPost(画布); }绘制函数是
{ 私人无效平局(帆布油画){ 涂料粉刷=新的油漆(); DisplayMetrics metdisplayMatrics =新DisplayMetrics(); 显示显示=((窗口管理器)getSystemService(WINDOW_SERVICE))getDefaultDisplay()。 display.getMetrics(metdisplayMatrics); canvas.save(); canvas.drawColor(0xff000000); mRecscreenRectangleFrame =新的Rect(0,0,(int)的(metdisplayMatrics.widthPixels * 2.0),metdisplayMatrics.heightPixels); 照片1 = BitmapFactory.de codeResource(getResources(),R.drawable.img1); canvas.drawBitmap(照片1,空,mRecscreenRectangleFrame,油漆); photo1.recycle(); System.gc()的; }现在如何把动态壁纸视差滚动效果。
@覆盖 公共无效onOffsetsChanged(浮动xOffset,浮yOffset, 浮xOffsetStep,浮yOffsetStep,诠释xPixelOffset, INT yPixelOffset){ super.onOffsetsChanged(xOffset,yOffset,xOffsetStep,yOffsetStep, xPixelOffset,yPixelOffset); WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext()); 查看查看=新景(getBaseContext()); myWallpaperManager.setWallpaperOffsets(view.getWindowToken(),xOffset,0F); }还没有成型............ 的
解决方案
呼叫 WallpaperManager.setWallpaperOffsets 指示壁纸滚动。
文档
因此,这应该居中壁纸:
WallpaperManager.setWallpaperOffsets(getWindowToken(),0.5F,0F);这应该是滚动到一边:
WallpaperManager.setWallpaperOffsets(getWindowToken(),0F,0F);这应该是滚动到另一侧:
WallpaperManager.setWallpaperOffsets(getWindowToken(),1F,0F);如果你要做到这一点,你应该确保你知道壁纸其实是可以滚动,或用户已经要求您启用滚动。许多设备都配置了壁纸是大小相同的画面,并且不滚动。
本文地址:IT屋 » Android的动态壁纸视差滚动效果