android - Scroll gallery to next page -


using widget.gallery display horizontally scrolling list of items. i've implemented paging in gallery seems standard technique: subclass gallery , implement:

@override public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) {         if (velocityx>0) {             onkeydown(keyevent.keycode_dpad_left, null);         } else {             onkeydown(keyevent.keycode_dpad_right, null);         } } 

when tapping gallery, fade next , previous image buttons. when clicking these, want gallery animated next/previous page, respectively. i've tried calling onkeydown next-button handler, strangely has no effect. absspinner has setselection(int position, boolean animate) animate ignored in gallery.

exactly toucan said, elaborate further (comments limits short):

the problem seems fact gallery doesn't let user scroll if no children exist in position yet. scrolltochild() culprit when trying inject event:

private boolean scrolltochild(int childposition) {     view child = getchildat(childposition);      if (child != null) {         int distance = getcenterofgallery() - getcenterofview(child);         mflingrunnable.startusingdistance(distance);         return true;     }      return false; } 

interestingly, if fling gallery fingers, cause child created. then, if let go of finger (going original position), , then press button activates onkeydown injection, it work flawlessly - because child there.

unfortunately there's no real solution since private in class. solution use setspacing(-1) or in gallery, left , right children created , visible, behind selected view.

as footnote, i'm baffled why private in class (or in other of android widget classes matter). 1 of things fixed small code change.

edit (aug 2012): future reference, rather trying use gallery kind of pattern (when want user swipe between different items while 1 of them visible), it's better use android's compatibility package's viewpager class. in opinion, compatibility package not celebrated should (it took me while notice of it). developers targeting android 2.x+, it's godsend.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -