public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
viewHolder.button.setText("button" + +position);
if(position == 0){
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams);
viewHolder.button.getLayoutParams();
params.height = 200;
params.width = 200;
viewHolder.itemView.setLayoutParams(params);
}else{
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams);
viewHolder.button.getLayoutParams();
params.height = RecyclerView.LayoutParams.WRAP_CONTENT;
params.width = RecyclerView.LayoutParams.WRAP_CONTENT;
viewHolder.itemView.setLayoutParams(params);
}
}
在GridView
的适配器中使用此代码我试图为GridView
的第一项提供自定义大小,但它会更改行中所有项目的大小,但会更改其他列的项目保持正常。
那么如何才能在GridView
中只更改一项?
答案 0 :(得分:0)
if(position == 0){
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams);
viewHolder.button.getLayoutParams();
params.height = 200;
params.width = 200;
viewHolder.itemView.setLayoutParams(params);
}else{
//make other item normal
}