首页 » Andorid » 临时分类 » 正文

InfiniteViewPager

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






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.

下载 (0)

发表评论