Animate a ImageView so it starts sliding in from the opposite side it slided out

Go To


Swag, I'm currently programming a android game and I need help with one problem. I want my background to slowly slide out in the right side of the screen, and at the same time make the exact same part that just slided out from the screen, slide in but from the left side. So almost like a marquee TextView.

Is there any simple way of doing this without having to create a set of different ImageViews and animate them differently.

Hope you understand, and that somebody got an answer to my question, cheers!

2012-04-04 17:03
by user1313414


The easiest way to do this would be to create a single large Bitmap that contains the entire background of your environment. Then each frame you display a different subsection of that image.

Here the gray box represents the entire background and the pink box represents the portion of the box you are actually drawing. Each time you redraw you would need calculate how much time has passed since the last draw and than use that delta_time to calculate the number of pixels to move the pink box.

To get a subimage from a bitmap you can simply use: createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)

Where source would be the gray box, x would represent how far along the pink box is, y would be 0 and width would be the width of the pink box and height would be the height of the background image.

enter image description here

Additionally I would recommend you checkout andengine its a great open-source game engine with a vibrant support community. They have great solutions for problems like this.

2012-04-04 17:12
by slayton