title: ViewPager with setCurrentItem(position, false) but with fade-in transition?
body: <p>I am trying to use the AHBottomNavigation (<a href="https://github.com/aurelhubert/ahbottomnavigation" rel="nofollow">https://github.com/aurelhubert/ahbottomnavigation</a>) and I am following its demo app for make my own.</p>
  
  <p>In the demo app it uses ViewPager and FragmentPagerAdapter to change between fragments, and everything is working perfectly.</p>
  
  <p>My problem is, I want to add a fade-in fade-out transition between the fragments, I had tried to change this:</p>
  
  <pre><code>viewPager.setCurrentItem(position, false);
  </code></pre>
  
  <p>for</p>
  
  <pre><code>viewPager.setCurrentItem(position);
  </code></pre>
  
  <p>And I had added this in my MainActivity:</p>
  
  <pre><code>viewPager.setPageTransformer(false, new FadePageTransformer());
  
  ...
  
  public class FadePageTransformer implements ViewPager.PageTransformer {
      public void transformPage(View view, float position) {
          view.setTranslationX(view.getWidth() * -position);
  
          if(position &lt;= -1.0F || position &gt;= 1.0F) {
              view.setAlpha(0.0F);
          } else if( position == 0.0F ) {
              view.setAlpha(1.0F);
          } else {
              // position is between -1.0F &amp; 0.0F OR 0.0F &amp; 1.0F
              view.setAlpha(1.0F - Math.abs(position));
          }
      }
  }
  </code></pre>
  
  <p>It actually works, but if I want to go from the first fragment to the last one, it shows all the fragments between them, like a scroll view.</p>
  
  <p>It has a method in the Fragment class (DemoFragment) that I think I can use for a fade-in fade-out transition, but I have no idea of how to implement it, this is the method:</p>
  
  <pre><code>/**
   * Called when a fragment will be displayed
   */
  public void willBeDisplayed() {
      // Do what you want here, for example animate the content
  }
  </code></pre>
  
  <p>Sorry, I am new in android, I still learning, and I hope you can help me, thanks!</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I want to add a cross-fade animation between the fragments, like the example in Material Design (<a href="https://www.google.com/design/spec/components/bottom-navigation.html#bottom-navigation-behavior" rel="nofollow">https://www.google.com/design/spec/components/bottom-navigation.html#bottom-navigation-behavior</a>)</p>
  
  <blockquote>
    <p>Transition between active and inactive views using a cross-fade
    animation.</p>
  </blockquote>