Skip to content Skip to sidebar Skip to footer

Smooth Endles Scrolling Background With Canvas?

Welcome all I have a background image and what I want is for it to be moving slowly to the right and when the image has reach the right end of the screen with the end of the left s

Solution 1:

assuming you don't want for user to scroll this background by own you may use TranslateAnimation with INFINITE param for repeat mode, it will be smooth. create 2 ImageViews horizontally (or even simple Views and setting Bitmap as background) and move their parent. when first get off the screen remove it and add another on other side. this is for background photo/image filling whole screen, if you have other size background just add more ImageViews to create 2x or more summary length than width of the screen (which can be easly measured on in onCreate or wherever. Just create something like Adapter for background image or even you may tray existing projects/libs usually named smth like HorizontalScrollView with Adapter returning some large numer in getCount, e.g. Integer.MAX_VALUE

about Bitmap errors - note that Adapter don't destroy lost/lefting Views, but use them as next (recreates) - this is convertView in getView(...) method. use ViewHolder pattern and you will use only two Views with single Bitmap setting (same refrence). you may create just once your static background Bitmap in constructor and keep in LruCache preventing from recycle it. every device can handle bitmap with same size as screen

Post a Comment for "Smooth Endles Scrolling Background With Canvas?"