添加如下依赖compile 'com.android.support:recyclerview-v7:25.3.1'
思维导图如下
代码片段如下:
// LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
// linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);//VERTICAL是垂直布局,HORIZONTAL是水平布局
// GridLayoutManager gridLayoutManager=new GridLayoutManager(this,3);//一行有三个数据
StaggeredGridLayoutManager staggeredGridLayoutManager=new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);//VERTICAL垂直方向的瀑布流,HORIZONTAL水平方向的瀑布流,
recyclerView.setLayoutManager(staggeredGridLayoutManager);
recyclerView.setAdapter(new shipeiqi());
class shipeiqi extends RecyclerView.Adapter<viewholder>
{
@Override
public viewholder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.buju,null);
viewholder viewholder=new viewholder(view);
return viewholder;
}
@Override
public void onBindViewHolder(viewholder holder, int position) {
holder.textView1.setText(list.get(position).getName());
holder.textView.setText(String.valueOf(list.get(position).getId()));
}
@Override
public int getItemCount() {
return list.size();
}
}
class viewholder extends RecyclerView.ViewHolder
{
TextView textView;
TextView textView1;
public viewholder(View itemView) {
super(itemView);
textView= (TextView) itemView.findViewById(R.id.textView);
textView1= (TextView) itemView.findViewById(R.id.textView1);
}
}