我正在尝试在 StaggeredGrid 中实现自定义 Rowspan
如何动态更改 StaggeredGridLayout 的行跨度。@Gabriele Mariotti 建议了一种实现
StaggeredGridLayoutManager.LayoutParams layoutParams =StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams();
layoutParams.setFullSpan(true);
但我无法让它工作。请建议我一些方法来实现这一点。
这是我的适配器类的代码,它将回收器适配器与视图持有者类一起扩展为嵌套类
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
LayoutInflater inflater;
Context context;
List<Information> data= Collections.emptyList();
public MyAdapter(Context context,List<Information>data)
{
inflater= LayoutInflater.from(context);
this.context=context;
this.data=data;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view=inflater.inflate(R.layout.custom_layout,parent,false);
MyViewHolder holder=new MyViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Information current=data.get(position);
holder.imageView.setImageResource(current.iconid);
if(position==0) {
StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
layoutParams.setFullSpan(true);
}
}
@Override
public int getItemCount() {
return 8;
}
class MyViewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
public MyViewHolder(View itemView) {
super(itemView);
imageView= (ImageView) itemView.findViewById(R.id.image);
}
}
}