title: Smooth endles scrolling background with canvas?
body: <p>Welcome all</p>
  
  <p>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 starting side of the image, the image must start again showing the start of the right side, as an infinite horizontal scroll.</p>
  
  <p>How can this be achieved without generating bitmap overflow memory exceptions?</p>
  
  <p>I tryed it drawing two times the bitmap with canvas... but it is not smooth, it is very creepy with jumps and not optimized:</p>
  
  <pre><code>universeBitmap = Bitmap.createScaledBitmap(universeBitmap, sw, sh, false); 
  
      universeView = new View(this){
  
          @Override
          protected void onDraw(Canvas canvas) {
              super.onDraw(canvas);
  
              if (paused==true){
                  canvas.drawBitmap(universeBitmap, universeX, 0, null);          
                  return;
              }
              long currentTime=System.currentTimeMillis();
              if ((currentTime-lastdrawTime)&gt;100){                    
                  if (universeX&gt;sw){
                      universeX=0;
                  }
                  lastdrawTime=currentTime;
                  universeX+=1;
              }
              canvas.drawBitmap(universeBitmap, universeX, 0, null);
              canvas.drawBitmap(universeBitmap, universeX-sw, 0, null);
              invalidate();
          }   
      };
  </code></pre>
  
  <p>I also tried without invalidating the view each 100ms, but with a thread and a handler, and same result.... creepy non smooth movement:</p>
  
  <pre><code>universeBitmap = Bitmap.createScaledBitmap(universeBitmap, sw, sh, false); 
  
              universeView = new View(this){
  
                  @Override
                  protected void onDraw(Canvas canvas) {
                      super.onDraw(canvas);               
                      canvas.drawBitmap(universeBitmap, universeX, 0, null);
                      canvas.drawBitmap(universeBitmap, universeX-sw, 0, null);
                  }   
              };
  .
  .
  .
          Handler handler=new Handler(){
              @Override
              public void handleMessage(Message msg) {
                  if (universeX&gt;sw){
                      universeX=0;
                  }
                  universeView.invalidate();
                  universeX+=1;
              }
          };  
  
  .
  .
  .
  
       public void run() {
              try {
                 while( !backgroundThread.interrupted() ) {
                     synchronized(this){  
                         handler.sendEmptyMessage(0);   
                         wait(100);
                     }    
                 }
      }
  </code></pre>
  
  <p>Thanks</p>