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

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

implementation 'com.chenlittleping:recyclercoverflow:1.0.6'

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

 <recycler.coverflow.RecyclerCoverFlow
            android:id="@+id/rcf_cinema_flow"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_300"
            android:layout_below="@+id/lin_cinema_lay_xq" />

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

   public class CinemaFlowAdapter extends RecycleAdapter<CinemaFlowBean.ResultBean> {
 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());
}
}

条目

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RelativeLayout
    android:layout_width="@dimen/dp_180"
    android:layout_height="@dimen/dp_258"
    android:background="@drawable/flow_5ra">

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/simp_cinema_flow"
        android:layout_width="@dimen/dp_180"
        android:layout_height="@dimen/dp_258"
        app:roundedCornerRadius="@dimen/dp_8dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_36"
        android:background="@drawable/shape_m_r_bg"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/text_cinema_flow1"
            android:layout_width="0dp"
            android:layout_height="@dimen/dp_36"
            android:layout_marginLeft="@dimen/dp_10"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="@color/colorD8d8d8"
            android:textSize="@dimen/sp_16" />

        <TextView
            android:id="@+id/text_cinema_flow2"
            android:layout_width="0dp"
            android:layout_height="@dimen/dp_36"
            android:layout_alignParentBottom="true"
            android:layout_marginRight="@dimen/dp_10"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="@color/colorD8d8d8"
            android:textSize="@dimen/sp_12" />
    </LinearLayout>
</RelativeLayout>

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

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

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

public void setList(List<T> 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());                  
        }
    });
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值