title: Android: Moving background image while navigating through Views
body: <p>What I want to have is a background image, which behaves like the stock homescreen or the weather app here: <a href="https://youtube.com/watch?v=i2Oh4GL5wBE#t=0m54s" rel="nofollow noreferrer">https://youtube.com/watch?v=i2Oh4GL5wBE#t=0m54s</a></p>
  
  <p>I just need a not animated background image (like the road in that video) which scrolls "a bit" while swiping to another view.
  In my app, I would like to swipe through some ListViews with a scrolling background.</p>
  
  <p>What I've tested:</p>
  
  <ul>
  <li>ViewFlipper: I used big image and cut it vertically into 5 pieces. Then I set those cutted images in each Layout (displaying the ListViews) as background. </li>
  <li>HorizontalScrollView: In the HorizontalScrollView I added a LinearLayout and set the big image as background. Then I used GestureDectector to add "snapping" when swiping through the ListViews.</li>
  </ul>
  
  <p>Both worked, but that requires a really big image and I'm not sure if it scales correctly to different screen sizes. Also it doesn't behave like the original homescreen, where the background moves just a little bit while the foreground changes to the next View.</p>
  
  <p>I read the post here: <a href="https://stackoverflow.com/questions/2943619/android-make-application-background-behave-like-homescreen-background">https://stackoverflow.com/questions/2943619/android-make-application-background-behave-like-homescreen-background</a></p>
  
  <p>I checked the recommended Launcher.java which led me to the Workspace.java:</p>
  
  <p><a href="https://android.googlesource.com/platform/packages/apps/Launcher2/+/master/src/com/android/launcher2/Workspace.java" rel="nofollow noreferrer">https://android.googlesource.com/platform/packages/apps/Launcher2/+/master/src/com/android/launcher2/Workspace.java</a></p>
  
  <p>As far as I understand, it uses the WallpaperManager by setting Offsets.</p>
  
  <pre><code> mWallpaperManager.setWallpaperOffsets(getWindowToken(),
                   Math.max(0.f, Math.min(mScrollX/(float)scrollRange, 1.f)), 0);
  </code></pre>
  
  <p>API says: </p>
  
  <blockquote>
    <p>setWallpaperOffsets(IBinder
    windowToken, float xOffset, float
    yOffset) 
    Set the position of the
    current wallpaper within any larger
    space, when that wallpaper is visible
    behind the given window.</p>
  </blockquote>
  
  <p>But as far as I understand, this just changes the background image of the phone itself.</p>
  
  <p>What can I do? Do you know an open source application or sample code which does the same?
  Probably I have to draw Canvas myself (never did before). Please give me some advice.</p>