Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Exactly what toucan said, but to elaborate further (comments limits are too short):</p> <p>The problem seems to be the fact that the <code>Gallery</code> doesn't let the user scroll if no children exist in that position yet. <code>scrollToChild()</code> is the culprit when trying to inject the event:</p> <pre><code>private boolean scrollToChild(int childPosition) { View child = getChildAt(childPosition); if (child != null) { int distance = getCenterOfGallery() - getCenterOfView(child); mFlingRunnable.startUsingDistance(distance); return true; } return false; } </code></pre> <p>Interestingly, if you fling the gallery with your fingers, it will cause the child to be created. Then, if you let go of your finger (going back to the original position), and <em>then</em> press the button that activates the <code>onKeyDown</code> injection, <em>it will work flawlessly</em> - because the child is there.</p> <p>Unfortunately there's no real solution since everything is private in that class. The only solution is to use <code>setSpacing(-1)</code> or something in the gallery, so left and right children are always created and visible, but just behind the currently selected view.</p> <p>As a footnote, I'm really baffled as to why everything is private in that class (or in any other of the Android widget classes for that matter). This is one of those things that could easily be fixed with some small code change.</p> <p><strong>Edit (Aug 2012):</strong> For future reference, rather than trying to use a Gallery for this kind of pattern (when you want the user to swipe between different items while only one of them is visible), it's much better to use the Android's <a href="http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html" rel="nofollow">compatibility package's <code>ViewPager</code> class</a>. In my opinion, the compatibility package is not as celebrated as it should be (it took me a while to get notice of it). For developers targeting Android 2.x+, it's a godsend.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload