Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To implement this the way you have started, you'll need to add an <a href="http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html" rel="noreferrer">AnimationListener</a> so that you can detect the beginning and ending of an animation. When onAnimationEnd() for the fade out is called, you can set the visibility of your ImageView object to View.INVISIBLE, switch the images and start your fade in animation - you'll need another AnimationListener here too. When you receive onAnimationEnd() for your fade in animation, set the ImageView to be View.VISIBLE and that should give you the effect you're looking for.</p> <p>I've implemented a similar effect before, but I used a <a href="http://developer.android.com/reference/android/widget/ViewSwitcher.html" rel="noreferrer">ViewSwitcher</a> with 2 ImageViews rather than a single ImageView. You can set the "in" and "out" animations for the ViewSwitcher with your fade in and fade out so it can manage the AnimationListener implementation. Then all you need to do is alternate between the 2 ImageViews.</p> <p><strong>Edit:</strong> To be a bit more useful, here is a quick example of how to use the ViewSwitcher. I have included the full source at <a href="https://github.com/aldryd/imageswitcher" rel="noreferrer">https://github.com/aldryd/imageswitcher</a>.</p> <p><strong>activity_main.xml</strong></p> <pre><code> &lt;ViewSwitcher android:id="@+id/switcher" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:inAnimation="@anim/fade_in" android:outAnimation="@anim/fade_out" &gt; &lt;ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="fitCenter" android:src="@drawable/sunset" /&gt; &lt;ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="fitCenter" android:src="@drawable/clouds" /&gt; &lt;/ViewSwitcher&gt; </code></pre> <p><strong>MainActivity.java</strong></p> <pre><code> // Let the ViewSwitcher do the animation listening for you ((ViewSwitcher) findViewById(R.id.switcher)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ViewSwitcher switcher = (ViewSwitcher) v; if (switcher.getDisplayedChild() == 0) { switcher.showNext(); } else { switcher.showPrevious(); } } }); </code></pre>
    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