title: Want to start animation on viewpager page but pages are preloading
body: <p>In my projects I have several screen(Fragments) and I want to give animation to the fragments elements(views). I have used view pager and viewpager adapter and fragments. The main problems I am facing- </p>
  
  <ol>
  <li>On starting of is loading 2 pages like on start it is loading page1 and page 2. If swiping to second page then it is loading 3rd page automatically.</li>
  <li>I need to show the animation for the view(RelativeLayout) which is using <a href="http://www.aurelienribon.com/blog/projects/universal-tween-engine/" rel="nofollow noreferrer">Universal tween engine</a>.</li>
  </ol>
  
  <p>Is there something wrong with the code? </p>
  
  <p>Here is the <strong>MainActivity.java</strong> code- </p>
  
  <pre><code>    public class MainActivity extends FragmentActivity {    
      ViewPager viewPager;
      PagerAdapter adapter;
      CirclePageIndicator mIndicator;
      private int mWidthScreen;
      private int mHeightScreen;
      private Bundle bundle;
      private List&lt;Fragment&gt; frgScreens;
      private int selectedtheme;
      private Handler mHandler = new Handler();
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.viewpager_main); // Get the view from viewpager_main.xml        
          buildargument();        
          initialisePaging(); // Page creating function       
      }
  
      private void initialisePaging(int theme) {
          viewPager = (ViewPager) findViewById(R.id.pager);       
          frgScreens = new Vector&lt;Fragment&gt;(); // clearing old entries        
          viewPager.setOffscreenPageLimit(0);
  viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
              @Override
              public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
                  //Loading fragment # position
  
                  //Instead of starting animation from onCreate start it from here 
                  //Only for the first time (for page 1) this callback will not trigger
              }
  
              @Override
              public void onPageSelected(int position) {
              }
  
              @Override
              public void onPageScrollStateChanged(int state) {
              }
          });
  
          frgScreens = this.basicThemes();
          // Bind result to ViewPagerAdapter
          adapter = new ViewPagerAdapter(this.getSupportFragmentManager(), frgScreens);
          this.viewPager.setAdapter(adapter);
      }
  
      /*
       * Basic fragments
       */
      private List&lt;Fragment&gt; basicThemes() {
          // declaring fragments Group Basic
          Fragment frgBasic1 = Fragment.instantiate(this, Basic1.class.getName());
          Fragment frgBasic2 = Fragment.instantiate(this, Basic2.class.getName());
          Fragment frgBasic3 = Fragment.instantiate(this, Basic3.class.getName());
          Fragment frgBasic4 = Fragment.instantiate(this, Basic4.class.getName()); 
          Fragment frgBasic5 = Fragment.instantiate(this, Basic5.class.getName()); 
  
          // Passing arguments
          frgBasic1.setArguments(bundle);
          frgBasic2.setArguments(bundle);
          frgBasic3.setArguments(bundle);
          frgBasic4.setArguments(bundle); 
          frgBasic5.setArguments(bundle);
  
  
  
          // Loading screens into Fragment list
          List&lt;Fragment&gt; frgBasicScreens = new Vector&lt;Fragment&gt;();
  
          frgBasicScreens.add(frgBasic1);
          frgBasicScreens.add(frgBasic2);
          frgBasicScreens.add(frgBasic3);
          frgBasicScreens.add(frgBasic4); 
          frgBasicScreens.add(frgBasic5);
  
      return frgBasicScreens;
  
  }
  
  private void getScreenHeightWidhth() {
      DisplayMetrics localDisplayMetrics = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
      this.mWidthScreen = localDisplayMetrics.widthPixels;
      this.mHeightScreen = localDisplayMetrics.heightPixels;
      mHandler.post(
              new DisplayToast(this, "Width Screen:" + mWidthScreen + ". Height Screen: " + mHeightScreen + "."));
  }
  
  private void buildargument() {
      this.bundle = new Bundle();
      bundle.putInt("mWidthScreen", this.mWidthScreen);
  }   
  
  @Override
  protected void onResume() {
      super.onResume();
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
  }}
  </code></pre>
  
  <p>Now <strong>ViewPagerAdapter.java</strong></p>
  
  <pre><code>public class ViewPagerAdapter extends FragmentPagerAdapter {    
  private List&lt;Fragment&gt; screens; 
  
  public ViewPagerAdapter(FragmentManager fm, List&lt;Fragment&gt; fragments ) {
      super(fm);      
      this.screens = fragments;       
  }
  
  @Override
  public Fragment getItem(int pos) {
      // getting the position of the item
      return this.screens.get(pos);       
  }
  
  @Override
  public int getCount() {
      // Getting the size of screen passed
      return this.screens.size();
  }}
  </code></pre>
  
  <p><strong>skinbase.java</strong> is the common class used by all the basics screen some shared methods.</p>
  
  <pre><code>public abstract class SkinsBase extends Fragment
  {
   protected int mWidthScreen;
   protected int mHeightScreen;
   public int skinHeight;
   public int skinWidth;
   public final int textShadowSize = 2;
   .................
   }
  </code></pre>
  
  <p>now <strong>basic1.java</strong></p>
  
  <pre><code>public class Basic1 extends SkinsBase { 
  private RelativeLayout mBlueBackground;
  private Handler mHandler = new Handler();
  private static final String TAG = "Basic1";
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      if (container == null) {
          return null;
      }       
      mContext = container.getContext();
      View v = inflater.inflate(R.layout.blank_viewpager_item, container, false);
      mLayoutForeground = (RelativeLayout) v.findViewById(R.id.relative);
  
      mBlueBackground = initshape(getResources().getColor(R.color.transparent_blue_80),this.mWidthScreen, (int) (0.10F * this.mWidthScreen), 0,(int) (0.12F *this.mWidthScreen));     
      this.mLayoutForeground.addView(this.mBlueBackground);   
  
      Log.e(TAG, "Inside basic 1 ");
      return v;
  }
  
  
  
  public RelativeLayout initshape(int intColor,int intWidthscreen, int intHeight, int intMerginLeft,int intMerginTop) {
      RelativeLayout localRelativeLayout = new RelativeLayout(this.mContext);             
      localRelativeLayout.setBackgroundColor(intColor);       
      RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(intWidthscreen, intHeight);
      localLayoutParams.setMargins(intMerginLeft, intMerginTop, 0, 0);
      localRelativeLayout.setLayoutParams(localLayoutParams);         
      return localRelativeLayout;
  }   
  
  public void onResume() {
      super.onResume();
  }
  @Override
  public void onPause() {
      super.onPause();
  }}
  </code></pre>
  
  <p>Same way other <strong>basic2.java, basic3.java, basic4.java.....</strong> are like <strong>basic1.java</strong> </p>
  
  <p>I need to apply animation to <strong>RelativeLayout</strong>. Is it possible? And I want the start of the animation when the page loads not before that.</p>