Android之RecyclerCoverFlow旋转木马相册的基本使用

**详细讲一下RecyclerCoverFlow的使用步骤 **
原作者Github地址https://github.com/ChenLittlePing/RecyclerCoverFlow:
1、引入依赖

implementation 'com.chenlittleping:recyclercoverflow:1.0.6'

2、在布局里使用这个 控件

 

3、 写适配器 这里的适配器就和普通的RecyclerView 适配器一样 附上我的完整代码
RecyclerCoverFlow适配器

   public class CinemaFlowAdapter extends RecycleAdapter {
 private  Context context;

public CinemaFlowAdapter(Context mcontext) {
    super(mcontext);
    this.context=mcontext;
}

@Override
protected int getLayoutId() {
    return R.layout.cinema_flow_item;
}

@Override
protected void convert(ViewHolder viewHolder, CinemaFlowBean.ResultBean resultBean, int postion) {
    viewHolder.setSimpleDraweViewUrl(R.id.simp_cinema_flow, resultBean.getImageUrl());
    viewHolder.setText(R.id.text_cinema_flow1,resultBean.getName());
    viewHolder.setText(R.id.text_cinema_flow2,resultBean.getDuration());
}
}

条目





    

    
        

        
    

继承的集成的适配器基类(也可以不抽取基类 直接写)

public abstract class RecycleAdapter extends RecyclerView.Adapter {
private List list = new ArrayList<>();
private Context mcontext;
private int postion;

public RecycleAdapter(Context mcontext) {
    this.mcontext = mcontext;
}

public void setList(List datas) {
    this.list.clear();
    this.list.addAll(datas);
    notifyDataSetChanged();
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, final int i) {
    View view = LayoutInflater.from(mcontext).inflate(getLayoutId(), null);
    return new ViewHolder(view, mcontext);
}

protected abstract int getLayoutId();

protected abstract void convert(ViewHolder viewHolder, T t, int postion);

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
    this.postion = i;
    convert(viewHolder, list.get(i), i);
}

@Override
public int getItemCount() {
    return list.size();
}
}

**4、找到控件,配置适配器 **

 flow = (RecyclerCoverFlow) findViewById(R.id.rcf_cinema_flow);//找控件
cinemaFlowAdapter = new CinemaFlowAdapter(context);//实例化适配器
    flow.setAdapter(cinemaFlowAdapter);//设置适配器
       cinemaFlowAdapter.setList(flowlist);//传集合数据  集合泛型类型根据自己情况写
    flow.setOnItemSelectedListener(new CoverFlowLayoutManger.OnSelected() {//滑动监听
        @Override
        public void onItemSelected(int position) {
            flag = position;
            Logger.d("Tagger", flowlist.get(position).getName());                  
        }
    });

你可能感兴趣的:(Android之RecyclerCoverFlow旋转木马相册的基本使用)