Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ViewFlipper not flipping
    text
    copied!<p>I have a ViewFlipper which should react to a fling gesture, but it does not.</p> <p>Activity</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { ... listView = this.getListView(); detector = new GestureDetector(this, new FlingGestureListener(listView)); ... } </code></pre> <p>FlingGestureListener</p> <pre><code>public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { int pos = source.pointToPosition(Math.round(e1.getX()), Math.round(e1.getY())); View v = source.getChildAt(pos - source.getFirstVisiblePosition()); System.out.println("fling: x=" + velocityX + " y=" + velocityY); try { IFlingable flingable = (IFlingable) v; if(velocityY &gt; -200 &amp;&amp; velocityY &lt; 200) { if(velocityX &lt; 0) flingable.fling(IFlingable.RIGHT_TO_LEFT); else if(velocityX &gt; 0) flingable.fling(IFlingable.LEFT_TO_RIGHT); } } catch(Exception e) {} return false; } </code></pre> <p>View with ViewFlipper which implements IFlingable</p> <pre><code>public void fling(int direction) { System.out.println("flip: " + direction); switch(direction) { case IFlingable.LEFT_TO_RIGHT: System.out.println("piep"); GUIHelper.setAnimationSlideLeftToRight(context, switcher); switcher.showNext(); break; case IFlingable.RIGHT_TO_LEFT: System.out.println("pup"); GUIHelper.setAnimationSlideRightToLeft(context, switcher); switcher.showPrevious(); break; } } </code></pre> <p>Layout</p> <pre><code>&lt;ViewFlipper android:id="@+id/viewSwitcher" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_weight="1" android:inAnimation="@anim/slide_in_left" android:outAnimation="@anim/slide_out_right"&gt; &lt;LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical"&gt; ... &lt;/LinearLayout&gt; ... &lt;/ViewFlipper&gt; </code></pre> <p>Log</p> <pre><code>fling: x=2542.3613 y=95.877945 flip: 0 piep </code></pre> <p>I get the right log messages so the showNext() on the ViewFlipper gets executed but it does not change its view on the gui. Am I missing something? I have another layout with a ViewSwitcher instead of the Flipper and that one works.</p> <p>EDIT:</p> <p>Here are the missing classes:</p> <pre><code>public class GUIHelper { ... public static void setAnimationSlideLeftToRight(Context context, ViewAnimator switcher) { Animation in = AnimationUtils.loadAnimation(context, R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(context, R.anim.slide_out_right); switcher.setInAnimation(in); switcher.setOutAnimation(out); } public static void setAnimationSlideRightToLeft(Context context, ViewAnimator switcher) { Animation in = AnimationUtils.loadAnimation(context, R.anim.slide_in_right); Animation out = AnimationUtils.loadAnimation(context, R.anim.slide_out_left); switcher.setInAnimation(in); switcher.setOutAnimation(out); } ... } public interface IFlingable { public static final int LEFT_TO_RIGHT = 0; public static final int RIGHT_TO_LEFT = 1; public void fling(int direction, boolean fling); } </code></pre>
 

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