An Android auto scroll ViewPager which can inifinite loop. And contains a animated indicator.
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;
mAutoLoopPager.setAutoPlay(boolean);
mAutoLoopPager.setAutoDuration(int);
mAutoLoopPager.setIndicatorAnimed(boolean);
layout_width
to match_parent
and leave the layout_height
with wrap_content
. In this case, the height will be calculated by the aspect ratio set here:mAutoLoopPager.setAspectRatio(float);
Thanks to gank.io. Where these images in this project are from.