wflfei / auto-loop-viewpager

An Android auto scroll ViewPager which can inifinite loop
Apache License 2.0
8 stars 5 forks source link

auto-loop-viewpager

An Android auto scroll ViewPager which can inifinite loop. And contains a animated indicator.

image

Useage

Custom your adapter extends RecycleAdapter:

private class MyAdapter extends RecycleAdapter<MyAdapter.ViewHolder> {
        public List<String> datas;

        @Override
        protected int getCount() {
            return null == datas ? 0 : datas.size();
        }

        @Override
        protected ViewHolder onCreateViewHolder(ViewGroup container) {
            SimpleDraweeView simpleDraweeView = new SimpleDraweeView(container.getContext());
            ViewHolder holder = new ViewHolder(simpleDraweeView);
            return holder;
        }

        @Override
        protected void onBindViewHolder(ViewHolder holder, int position) {
            holder.simpleDraweeView.setImageURI(Uri.parse(datas.get(position)));
        }

        @Override
        protected void onRecycleViewHolder(ViewHolder holder) {

        }

        public class ViewHolder extends RecycleAdapter.ViewHolder {
            private SimpleDraweeView simpleDraweeView;

            protected ViewHolder(@NonNull View view) {
                super(view);
                simpleDraweeView = ((SimpleDraweeView) view);
            }
        }
    }

And then:

mAutoLoopPager.setAdapter(new MyAdapter());

Also you can check the RecycleAdapter.java to see how does RecycleAdapter manage and recycle Views for the ViewPager;

Configration

mAutoLoopPager.setAutoPlay(boolean);
mAutoLoopPager.setAutoDuration(int);
mAutoLoopPager.setIndicatorAnimed(boolean);
mAutoLoopPager.setAspectRatio(float);

Thanks to gank.io. Where these images in this project are from.