onOffsetsChanged: move Bitmap

前端 未结 1 1947
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 16:01

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

相关标签:
1条回答
  • 2021-01-15 16:36

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

    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 :-)
    

    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.

    0 讨论(0)
提交回复
热议问题