title: Viewpager Recyclerview scroll lag
body: <p>I'm trying to implement viewpager for the mainpage having 4 fragments (fixed). The fragments on their own aren't lagging (and I am sure of this cause they were previously implemented through navigation drawer ).The fragments contain recyclerview which is lagging. It contains images . For loading the images I am using Glide. I've tried setEnabledNestedScrollingEnabled to false , but no such luck.For test purposes I was just testing with one fragment , even then it was lagging.</p>
  
  <p>MainActivity</p>
  
  <pre><code>package com.example.anubhavr.firebase;
  
  
  public class MainActivity extends AppCompatActivity {
  
  private Toolbar toolbar;
  private TabLayout tabLayout;
  private ViewPager viewPager;
  private int[] tabIcons = {R.drawable.fragment_one, R.drawable.fragment_two, R.drawable.fragment_three, R.drawable.fragment_four};
  private String[] names = {"Fragment 1", "Fragment 2", "Fragment 3", "Fragment 4"};
  private int isOffline;
  private FloatingActionButton floatingActionButton;
  private static int currentTab = 0;
  private final int RC_SIGN_IN = 1;
  private GoogleApiClient mGoogleApiClient;
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.tab_view_menu, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.menu_profile: {
              viewProfile();
              return true;
          }
          case R.id.menu_sign_out: {
              signout();
              return true;
          }
          case R.id.menu_store:
              {
              startVisitingStore();
              return true;
          }
          default:
              return super.onOptionsItemSelected(item);
      }
  }
  private void startVisitingStore(){
      Intent i = new Intent(this, StoreActivity.class);
      startActivity(i);
  }
  
  private void viewProfile() {
  
      Intent i = new Intent(this, ProfileActivity.class);
      startActivity(i);
  
  }
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      isOffline = getIntent().getIntExtra("isOffline", 0); //1 means is offline, 0 means is online
      toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      viewPager = (ViewPager) findViewById(R.id.viewpager);
      setupViewPager(viewPager);
  
      tabLayout = (TabLayout) findViewById(R.id.tabs);
      tabLayout.setupWithViewPager(viewPager);
      setupTabIcons();
  }
  
  
  private void setupTabIcons() {
  
      final TabLayout.Tab tab = tabLayout.getTabAt(0);
      Glide.with(this)
              .load(tabIcons[0])
              .override(42,42)
              .into(new SimpleTarget&lt;GlideDrawable&gt;() {
                  @Override
                  public void onResourceReady(GlideDrawable resource, GlideAnimation&lt;? super GlideDrawable&gt; glideAnimation) {
                      tab.setIcon(resource);
                  }
              });
  
  }
  
  private void setupViewPager(ViewPager viewPager) {
      ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
      Fragment_One one = new Fragment_One();
      Bundle bundle = new Bundle();
      bundle.putInt("isOffline", isOffline);
      mainActivity.setArguments(bundle);
      adapter.addFrag(one, names[0]);
  
      viewPager.setAdapter(adapter);
  
      viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
          }
  
          @Override
          public void onPageSelected(int position) {
              toolbar.setTitle(names[position]);
              currentTab = position;
  
          }
  
          @Override
          public void onPageScrollStateChanged(int state) {
  
          }
      });
  
  }
  
  class ViewPagerAdapter extends FragmentPagerAdapter {
      private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
      public ViewPagerAdapter(FragmentManager manager) {
          super(manager);
      }
  
      @Override
      public Fragment getItem(int position) {
          return mFragmentList.get(position);
      }
  
      @Override
      public int getCount() {
          return mFragmentList.size();
      }
  
      public void addFrag(Fragment fragment, String title) {
          mFragmentList.add(fragment);
          mFragmentTitleList.add(title);
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return null;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_height="match_parent"&gt;
  
  
          &lt;android.support.design.widget.TabLayout
              android:id="@+id/tabs"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:tabMode="fixed"
              app:tabGravity="fill"/&gt;
  
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/viewpager"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"  /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Fragment_One</p>
  
  <pre><code>public class Fragment_One extends Fragment implements GEventLoadMore {
  
      ......
      ......
  
      public void setView(final ArrayList&lt;GEventAdapter&gt; eventsArr) {
  
  
          listView = (RecyclerView) view.findViewById(R.id.listView);
          listView.setNestedScrollingEnabled(false);
  
          RecyclerView.ItemAnimator animator = listView.getItemAnimator();
  
          if (animator instanceof SimpleItemAnimator) {
              ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
          }
  
          mLinearLayoutManager = new LinearLayoutManager(getContext());
  
          listView.addItemDecoration(new VerticalSpaceItemDecoration(2));
  
          listView.setLayoutManager(mLinearLayoutManager);
  
          adapter = new Fragment_One_CustomAdapter(getContext(), R.layout.example, eventsArr);
  
          listView.setAdapter(adapter);
  
  
          listView.addOnScrollListener(new RecyclerView.OnScrollListener() {
              @Override
              public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                  super.onScrollStateChanged(recyclerView, newState);
  
                  if (eventsArr.size() &gt; 0) {
                      int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
                      if (lastVisiblePosition == recyclerView.getChildCount()) {
                          //progressDialog.show();
                          if(isOffline==0)
                              loadMoreFunction();
  
                      }
                  }
              }
  
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  
  
              }
          });
  
          restoreScrollPosition();
      }
  
  .....
  .....
  
  }
  </code></pre>