content: package me.angeldevil.autoscrollviewpager.demo;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.view.PagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.nostra13.universalimageloader.core.DisplayImageOptions;
  import com.nostra13.universalimageloader.core.ImageLoader;
  import com.nostra13.universalimageloader.core.assist.ImageScaleType;
  import com.viewpagerindicator.CirclePageIndicator;
  
  import me.angeldevil.autoscrollviewpager.AutoScrollViewPager;
  
  public class AutoScrollPagerFragment extends Fragment {
  
      private String[] imgs = {"http://h.hiphotos.baidu.com/image/w%3D1920%3Bcrop%3D0%2C0%2C1920%2C1080/sign=fed1392e952bd40742c7d7f449b9a532/e4dde71190ef76c6501a5c2d9f16fdfaae5167e8.jpg",
              "http://a.hiphotos.baidu.com/image/w%3D1920%3Bcrop%3D0%2C0%2C1920%2C1080/sign=25d477ebe51190ef01fb96d6fc2ba675/503d269759ee3d6df51a20cd41166d224e4adedc.jpg",
              "http://c.hiphotos.baidu.com/image/w%3D1920%3Bcrop%3D0%2C0%2C1920%2C1080/sign=70d2b81e60d0f703e6b291d53aca6a5e/0ff41bd5ad6eddc4ab1b5af23bdbb6fd5266333f.jpg"};
      private String[] titles = {"Page 1", "Page 2", "Page 3"};
  
      private DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
              .cacheOnDisk(true).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
  
      private Toast toast;
  
      public AutoScrollPagerFragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          return inflater.inflate(R.layout.fragment_auto_scroll_pager, container, false);
      }
  
      @Override
      public void onViewCreated(View view, Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
          AutoScrollViewPager pager = (AutoScrollViewPager) getView().findViewById(R.id.scroll_pager);
          final TextView title = (TextView) getView().findViewById(R.id.title);
          CirclePageIndicator indicator = (CirclePageIndicator) getView().findViewById(R.id.indicator);
  
          pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
              @Override
              public void onPageSelected(int i) {
                  title.setText(titles[i]);
              }
          });
  
          pager.setAdapter(new PagerAdapter() {
              @Override
              public int getCount() {
                  return imgs.length;
              }
  
              @Override
              public boolean isViewFromObject(View view, Object o) {
                  return view == o;
              }
  
              @Override
              public Object instantiateItem(ViewGroup container, int position) {
                  ImageView view = new ImageView(container.getContext());
                  view.setScaleType(ImageView.ScaleType.CENTER_CROP);
                  ImageLoader.getInstance().displayImage(imgs[position], view, options);
                  container.addView(view);
                  return view;
              }
  
              @Override
              public void destroyItem(ViewGroup container, int position, Object object) {
                  container.removeView((View) object);
              }
          });
  
          indicator.setViewPager(pager);
          indicator.setSnap(true);
  
          pager.setScrollFactor(5);
          pager.setOffscreenPageLimit(4);
          pager.startAutoScroll(2000);
          pager.setOnPageClickListener(new AutoScrollViewPager.OnPageClickListener() {
              @Override
              public void onPageClick(AutoScrollViewPager autoScrollPager, int position) {
                  if (toast != null) {
                      toast.cancel();
                  }
                  toast = Toast.makeText(getActivity(), "You clicked page: " + (position + 1),
                          Toast.LENGTH_SHORT);
                  toast.show();
              }
          });
      }
  }
  