onOffsetsChanged:移动位​​图 [英] onOffsetsChanged: move Bitmap

查看:124
本文介绍了onOffsetsChanged:移动位​​图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的位图,有屏幕的高度,并具有更大的宽度比屏幕上移动一点点向右或者如果用户更改桌面这样他就可以看到整个图像离开。

i want my Bitmap that has the height of the screen and has a bigger width than the screen to be moved a little bit to the right or left if the user changes the desktop so he can see the entire image.

下面是我的code,它只是工作的部分:

Here is my code that just works partially:

        int x = -1*(int)((xOffset*bmp.getWidth()));
        canvas.drawBitmap(bmp, x, 0, null);

谢谢!

推荐答案

您在onOffsetsChanged通过变量xPixels和yPixels得到确切的像素值()。看到这里我的回答:<一href="http://stackoverflow.com/questions/5208203/android-live-wallpaper-rescaling/5347525#5347525">android动态壁纸重新缩放

You get exact pixel values via the variables xPixels and yPixels in onOffsetsChanged(). See my answer here: android live wallpaper rescaling

例如,在onOffsetsChanged(),你可以设置一个私有类变量

For example, in onOffsetsChanged(), you can set a private class variable

mPixels = xPixels;

然后,在你的抽奖程序

Then, in your draw routine

holder = getSurfaceHolder();
c = holder.lockCanvas();
c.translate(mPixels, 0f);
// c.drawBitmap ... goes here :-)

通常情况下,你会希望有一个位图屏幕宽度的两倍,与您的作品集中在中间。例如:320像素的宽屏幕 - > 640像素的宽度的位图与从160至480万像素中心将为0在最左边的发射器屏幕(5),在-160的中心,和-320在最右边的屏幕

Typically, you will want a bitmap twice the width of your screen, with your artwork centered in the middle. For example: 320 pixel width screen -> 640 pixel width bitmap with "center" from 160 to 480. mPixels will be 0 at the left most launcher screen (of 5), -160 at the center, and -320 at the rightmost screen.

这篇关于onOffsetsChanged:移动位​​图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆