在GridView

时间:2016-03-09 06:53:47

标签: android gridview android-gridview android-inflate android-layoutparams

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中只更改一项?

1 个答案:

答案 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
}