RecyclerView的布局方式 AND点击事件setOnItemClickListener

xiaoxiao2021-02-28  19

 

GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2, RecyclerView.HORIZONTAL, false); mRvClass.setLayoutManager(gridLayoutManager);

//必须要有,默认的(listview的形式)// recy_view.setLayoutManager(new LinearLayoutManager(this));//横向(排成一排,不管有多少个,后面有个false和true)// recy_view.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false));//九宫格布局(垂直方向上的,4代表个数)// recy_view.setLayoutManager(new GridLayoutManager(this,4));//九宫格布局(水平方向上的)recy_view.setLayoutManager(new GridLayoutManager(this, 4, LinearLayoutManager.HORIZONTAL, false));

//用于点击事件private OnRecyclerViewItemClickListener mOnItemClickListener = null;public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {this.mOnItemClickListener = listener;}//define interfacepublic static interface OnRecyclerViewItemClickListener {void onItemClick(View view , int position);}

转载请注明原文地址: https://www.6miu.com/read-2150363.html

最新回复(0)