• Stars
    star
    282
  • Rank 146,549 (Top 3 %)
  • Language
    Java
  • License
    MIT License
  • Created about 9 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

InfiniteViewPager is a modified android ViewPager widget that allows infinite paging and auto-scrolling.

InfiniteViewpager

https://github.com/waylife/InfiniteViewPager

中文 English

Function

  • Automatically scroll to next page
  • Smoothly scrolls from the end page to the first page,so does first to end.
  • View reuse support, no worrying about OOM
  • With indicator support(Modification of ViewpagerIncicator)
  • Fluid when invoking ViewPager.setCurrentItem(), better than the common solution

Preview

Sample demo

Usage

Almost the same as the viewpager. Below are some steps.

define in xml layout

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="200dp">

            <com.zanlabs.widget.infiniteviewpager.InfiniteViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:visibility="visible" />

            <com.zanlabs.widget.infiniteviewpager.indicator.LinePageIndicator
                android:id="@+id/indicator"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                app:fillColor="#e3ffc7"
                app:pageColor="#5fff65" />
        </RelativeLayout>

implement the InfinitePagerAdapter

Similar as the implement of BaseAdapter. You need to overide the getView and getItemCount(not getCount) mehtod.

    @Override
     public View getView(int position, View view, ViewGroup container) {
         ViewHolder holder;
         if (view != null) {
             holder = (ViewHolder) view.getTag();
         } else {
             view = mInflater.inflate(R.layout.item_infinite_viewpager, container, false);
             holder = new ViewHolder(view);
             view.setTag(holder);
         }
         PagerItem item = mList.get(position);
         holder.position = position;
         holder.name.setText(item.getName());
         holder.description.setText(item.getDesc()+"position:"+position);
         Picasso.with(mContext).load(item.getImageUrl()).placeholder(R.mipmap.bg_loding_horizontal).into(holder.image);
         return view;
     }


     @Override
     public int getItemCount() {
         return mList==null?0:mList.size();
     }

setup in activity or fragment.

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        //
        MockPagerAdapter pagerAdapter = new MockPagerAdapter(this);
        pagerAdapter.setDataList(MockDataGenerator.getViewPagerData());
        mViewPager.setAdapter(pagerAdapter);
        mViewPager.setAutoScrollTime(5000);
        mViewPager.startAutoScroll();
        mLineIndicator.setViewPager(mViewPager);
        //
      }

    @Override
    public void onStart() {
        super.onStart();
        if (mViewPager != null)
            mViewPager.startAutoScroll();
    }

    @Override
    public void onStop() {
        if (mViewPager != null)
            mViewPager.stopAutoScroll();
        super.onStop();
    }

More You can refer to the sample project.

Thanks to

License

The MIT License.