横向滑动的Recycleview

Posted 和平world

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了横向滑动的Recycleview相关的知识,希望对你有一定的参考价值。

布局文件代码


<span style="font-size:18px;"><android.support.v7.widget.RecyclerView
        android:id="@+id/rv_PeiTaoPicHorizontal"
        android:layout_width="match_parent"
        android:layout_height="89dp"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="20dp"
        ></span>

适配器代码


<span style="font-size:18px;">public class PeiTaoXunJiaDetailRecyAdapter extends RecyclerView.Adapter<PeiTaoXunJiaDetailRecyAdapter.myViewHolder> {

    private Context context;
    private List arrayList;

    public PeiTaoXunJiaDetailRecyAdapter(Context context, List arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public myViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        myViewHolder holder = new myViewHolder(View.inflate(parent.getContext(), R.layout.activity_peitaoxunjiarecyitem, null));
        return holder;
    }

    @Override
    public void onBindViewHolder(myViewHolder holder, int position) {

    }


    @Override
    public int getItemCount() {
        return arrayList==null ? 0 : arrayList.size();
    }

    public class myViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_buchongPic)
        ImageView ivBuchongPic;

        public myViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(itemView);
        }
    }

}</span>
主Activity代码

 <span style="font-size:18px;">LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvPeiTaoPicHorizontal.setLayoutManager(linearLayoutManager);
        rvPeiTaoPicHorizontal.setAdapter(new PeiTaoXunJiaDetailRecyAdapter(getBaseContext(),arrayList));</span>



以上是关于横向滑动的Recycleview的主要内容,如果未能解决你的问题,请参考以下文章

轮播滑动方向的 Kivy RecycleView 不起作用

FragmentStatePageAdapter 缓存,重新创​​建活动后如何引用旧片段? (对于前 - 横向模式)

怎么关闭android recycleview自带的滑动效果

setOnClickListener RecycleView(在一个片段中)导航到另一个片段

Recycleview 没有出现在片段中

ListView嵌套RecycleView滑动卡顿问题的优化方案