title: Android: Programmatically animate between images in Gallery widget
body: <p>Note: As of Jellybean the gallery widget is deprecated. A <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html" rel="nofollow noreferrer">ViewPager</a> should be used instead.</p>
  
  <hr>
  
  <p>I'd like to programmatically move between images in the Gallery widget, with animation.</p>
  
  <p>I can change the currently displaying image using the <code>setSelection(int position)</code> method, however that does not animate. Then there's <code>setSelection(int position, bool animate)</code> but the extra boolean on the end there doesn't appear to do anything.</p>
  
  <p>In the <a href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/widget/Gallery.java" rel="nofollow noreferrer">source of Gallery</a> it appears that it can handle DPAD key-presses, so a work-around I thought of was to fake the key-presses. Eg.</p>
  
  <pre><code>dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT))
  </code></pre>
  
  <p>However I can't get this working for some reason. Anyone tried this?</p>
  
  <p>I notice three of the widget's methods I'd love to use <code>moveNext()</code>, <code>movePrevious()</code> and <code>scrollToChild()</code> are all private and unusable.</p>
  
  <p>Does anyone know how I might be able to do this?</p>